Part Number Hot Search : 
MB252 01726203 AD22103 2SD14 HMC28606 8913K XXXCB TK61023
Product Description
Full Text Search
 

To Download MKL04Z16VFM4 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  kl04 sub-family reference manual supports: mkl04z8vfk4, mkl04z16vfk4, mkl04z32vfk4, mkl04z8vlc4, mkl04z16vlc4, mkl04z32vlc4, mkl04z8vfm4, MKL04Z16VFM4, mkl04z32vfm4, mkl04z16vlf4, and mkl04z32vlf4 document number: kl04p48m48sf1rm rev. 3.1, november 2012
kl04 sub-family reference manual, rev. 3.1, november 2012 2 freescale semiconductor, inc.
contents section number title page chapter 1 about this document 1.1 overview ....................................................................................................................................................................... 29 1.1.1 purpose ......................................................................................................................................................... 29 1.1.2 audience ...................................................................................................................................................... 29 1.2 conventions .................................................................................................................................................................. 29 1.2.1 numbering systems ...................................................................................................................................... 29 1.2.2 typographic notation ................................................................................................................................... 30 1.2.3 special terms ................................................................................................................................................ 30 chapter 2 introduction 2.1 overview ....................................................................................................................................................................... 31 2.2 kinetis l series ............................................................................................................................................................. 31 2.3 kl04 sub-family introduction..................................................................................................................................... 34 2.4 module functional categories........................................................................................................................................ 35 2.4.1 arm? cortex?-m0+ core modules ......................................................................................................... 35 2.4.2 system modules ........................................................................................................................................... 36 2.4.3 memories and memory interfaces ............................................................................................................... 37 2.4.4 clocks........................................................................................................................................................... 37 2.4.5 security and integrity modules .................................................................................................................... 37 2.4.6 analog modules ........................................................................................................................................... 38 2.4.7 timer modules ............................................................................................................................................. 38 2.4.8 communication interfaces ........................................................................................................................... 39 2.4.9 human-machine interfaces .......................................................................................................................... 39 2.5 orderable part numbers................................................................................................................................................. 39 chapter 3 chip configuration 3.1 introduction ................................................................................................................................................................... 41 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 3
section number title page 3.2 module to module interconnects .................................................................................................................................. 41 3.2.1 module to module interconnects ................................................................................................................. 41 3.2.2 analog reference options ............................................................................................................................. 43 3.3 core modules ................................................................................................................................................................ 44 3.3.1 arm cortex-m0+ core configuration ....................................................................................................... 44 3.3.2 nested vectored interrupt controller (nvic) configuration...................................................................... 46 3.3.3 asynchronous wake-up interrupt controller (awic) configuration............................................................ 50 3.4 system modules ............................................................................................................................................................ 51 3.4.1 sim configuration ....................................................................................................................................... 51 3.4.2 system mode controller (smc) configuration........................................................................................... 52 3.4.3 pmc configuration ...................................................................................................................................... 52 3.4.4 low-leakage wake-up unit (llwu) configuration ................................................................................. 53 3.4.5 mcm configuration .................................................................................................................................... 55 3.4.6 crossbar-light switch configuration .......................................................................................................... 56 3.4.7 peripheral bridge configuration .................................................................................................................. 57 3.4.8 dma request multiplexer configuration ...................................................................................................... 58 3.4.9 dma controller configuration ................................................................................................................... 61 3.4.10 computer operating properly (cop) watchdog configuration.................................................................. 61 3.5 clock modules .............................................................................................................................................................. 64 3.5.1 mcg configuration ..................................................................................................................................... 64 3.5.2 osc configuration ...................................................................................................................................... 65 3.6 memories and memory interfaces ................................................................................................................................ 66 3.6.1 flash memory configuration ....................................................................................................................... 66 3.6.2 flash memory controller configuration ..................................................................................................... 68 kl04 sub-family reference manual, rev. 3.1, november 2012 4 freescale semiconductor, inc.
section number title page 3.6.3 sram configuration ................................................................................................................................... 69 3.7 analog ........................................................................................................................................................................... 71 3.7.1 12-bit sar adc configuration .................................................................................................................. 71 3.7.2 cmp configuration ...................................................................................................................................... 75 3.8 timers ........................................................................................................................................................................... 77 3.8.1 timer/pwm module configuration ............................................................................................................ 77 3.8.2 pit configuration ........................................................................................................................................ 79 3.8.3 low-power timer configuration ................................................................................................................... 81 3.8.4 rtc configuration ....................................................................................................................................... 82 3.9 communication interfaces ............................................................................................................................................ 84 3.9.1 spi configuration ......................................................................................................................................... 84 3.9.2 i2c configuration ........................................................................................................................................ 85 3.9.3 uart configuration ................................................................................................................................... 85 3.10 human-machine interfaces (hmi) ................................................................................................................................ 87 3.10.1 gpio configuration ..................................................................................................................................... 87 chapter 4 memory map 4.1 introduction ................................................................................................................................................................... 91 4.2 system memory map..................................................................................................................................................... 91 4.3 flash memory map ....................................................................................................................................................... 92 4.3.1 alternate non-volatile irc user trim description .................................................................................... 92 4.4 sram memory map ..................................................................................................................................................... 93 4.5 bit manipulation engine ............................................................................................................................................... 93 4.6 peripheral bridge (aips-lite) memory map................................................................................................................. 94 4.6.1 read-after-write sequence and required serialization of memory operations.............................................. 94 4.6.2 peripheral bridge (aips-lite) memory map .............................................................................................. 95 4.6.3 modules restricted access in user mode ................................................................................................... 98 4.7 private peripheral bus (ppb) memory map.................................................................................................................. 98 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 5
section number title page chapter 5 clock distribution 5.1 introduction ................................................................................................................................................................... 101 5.2 programming model...................................................................................................................................................... 101 5.3 high-level device clocking diagram ............................................................................................................................ 101 5.4 clock definitions ........................................................................................................................................................... 102 5.4.1 device clock summary ................................................................................................................................. 103 5.5 internal clocking requirements ..................................................................................................................................... 105 5.5.1 clock divider values after reset .................................................................................................................... 105 5.5.2 vlpr mode clocking ................................................................................................................................... 106 5.6 clock gating ................................................................................................................................................................. 106 5.7 module clocks ............................................................................................................................................................... 106 5.7.1 pmc 1-khz lpo clock ................................................................................................................................ 107 5.7.2 cop clocking ............................................................................................................................................... 108 5.7.3 rtc clocking ............................................................................................................................................... 108 5.7.4 lptmr clocking.......................................................................................................................................... 109 5.7.5 tpm clocking ............................................................................................................................................... 109 5.7.6 uart clocking ............................................................................................................................................ 110 chapter 6 reset and boot 6.1 introduction ................................................................................................................................................................... 111 6.2 reset.............................................................................................................................................................................. 111 6.2.1 power-on reset (por) .................................................................................................................................. 112 6.2.2 system reset sources .................................................................................................................................... 112 6.2.3 mcu resets ................................................................................................................................................. 115 6.2.4 reset pin ..................................................................................................................................................... 116 6.2.5 debug resets ................................................................................................................................................. 117 6.3 boot ............................................................................................................................................................................... 118 6.3.1 boot sources ................................................................................................................................................. 118 kl04 sub-family reference manual, rev. 3.1, november 2012 6 freescale semiconductor, inc.
section number title page 6.3.2 fopt boot options ....................................................................................................................................... 118 6.3.3 boot sequence .............................................................................................................................................. 119 chapter 7 power management 7.1 introduction ................................................................................................................................................................... 121 7.2 clocking modes ............................................................................................................................................................ 121 7.2.1 partial stop ................................................................................................................................................... 121 7.2.2 dma wakeup .............................................................................................................................................. 122 7.2.3 compute operation ...................................................................................................................................... 123 7.2.4 peripheral doze ............................................................................................................................................ 124 7.2.5 clock gating ................................................................................................................................................ 125 7.3 power modes ................................................................................................................................................................. 125 7.4 entering and exiting power modes ............................................................................................................................... 127 7.5 module operation in low power modes...................................................................................................................... 127 chapter 8 security 8.1 introduction ................................................................................................................................................................... 131 8.2 flash security ............................................................................................................................................................... 131 8.3 security interactions with other modules ..................................................................................................................... 131 8.3.1 security interactions with debug ................................................................................................................. 132 chapter 9 debug 9.1 introduction ................................................................................................................................................................... 133 9.2 debug port pin descriptions......................................................................................................................................... 133 9.3 swd status and control registers .................................................................................................................................. 134 9.3.1 mdm-ap control register .......................................................................................................................... 135 9.3.2 mdm-ap status register ............................................................................................................................ 136 9.4 debug resets ................................................................................................................................................................ 138 9.5 micro trace buffer (mtb) ........................................................................................................................................... 139 9.6 debug in low power modes ........................................................................................................................................ 139 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 7
section number title page 9.7 debug & security ......................................................................................................................................................... 139 chapter 10 signal multiplexing and signal descriptions 10.1 introduction ................................................................................................................................................................... 141 10.2 signal multiplexing integration .................................................................................................................................... 141 10.2.1 port control and interrupt module features .................................................................................................. 142 10.2.2 clock gating ................................................................................................................................................. 143 10.2.3 signal multiplexing constraints .................................................................................................................... 143 10.3 pinout ............................................................................................................................................................................ 143 10.3.1 kl04 signal multiplexing and pin assignments ........................................................................................... 143 10.3.2 kl04 pinouts ............................................................................................................................................... 145 10.4 module signal description tables................................................................................................................................ 149 10.4.1 core modules ............................................................................................................................................... 149 10.4.2 system modules ........................................................................................................................................... 150 10.4.3 clock modules ............................................................................................................................................. 150 10.4.4 memories and memory interfaces ............................................................................................................... 150 10.4.5 analog .......................................................................................................................................................... 150 10.4.6 timer modules ............................................................................................................................................. 151 10.4.7 communication interfaces ........................................................................................................................... 152 10.4.8 human-machine interfaces (hmi) .............................................................................................................. 152 chapter 11 port control and interrupts (port) 11.1 introduction ................................................................................................................................................................... 153 11.2 overview ....................................................................................................................................................................... 153 11.2.1 features ........................................................................................................................................................ 153 11.2.2 modes of operation ...................................................................................................................................... 154 11.3 external signal description............................................................................................................................................ 154 11.4 detailed signal description............................................................................................................................................ 155 kl04 sub-family reference manual, rev. 3.1, november 2012 8 freescale semiconductor, inc.
section number title page 11.5 memory map and register definition............................................................................................................................. 155 11.5.1 pin control register n (port x _pcr n )....................................................................................................... 158 11.5.2 global pin control low register (port x _gpclr) .................................................................................. 160 11.5.3 global pin control high register (port x _gpchr) ................................................................................. 161 11.5.4 interrupt status flag register (port x _isfr) ............................................................................................ 161 11.6 functional description................................................................................................................................................... 162 11.6.1 pin control .................................................................................................................................................... 162 11.6.2 global pin control ........................................................................................................................................ 163 11.6.3 external interrupts ........................................................................................................................................ 163 chapter 12 system integration module (sim) 12.1 introduction ................................................................................................................................................................... 165 12.1.1 features ........................................................................................................................................................ 165 12.2 memory map and register definition............................................................................................................................. 165 12.2.1 system options register 1 (sim_sopt1) .................................................................................................. 167 12.2.2 sopt1 configuration register (sim_sopt1cfg) .................................................................................... 167 12.2.3 system options register 2 (sim_sopt2) .................................................................................................. 168 12.2.4 system options register 4 (sim_sopt4) .................................................................................................. 170 12.2.5 system options register 5 (sim_sopt5) .................................................................................................. 171 12.2.6 system options register 7 (sim_sopt7) .................................................................................................. 172 12.2.7 system device identification register (sim_sdid)................................................................................... 174 12.2.8 system clock gating control register 4 (sim_scgc4) ............................................................................ 176 12.2.9 system clock gating control register 5 (sim_scgc5) ............................................................................ 177 12.2.10 system clock gating control register 6 (sim_scgc6) ............................................................................ 179 12.2.11 system clock gating control register 7 (sim_scgc7) ............................................................................ 180 12.2.12 system clock divider register 1 (sim_clkdiv1) ................................................................................... 181 12.2.13 flash configuration register 1 (sim_fcfg1) ........................................................................................... 183 12.2.14 flash configuration register 2 (sim_fcfg2) ........................................................................................... 184 12.2.15 unique identification register mid-high (sim_uidmh) .......................................................................... 185 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 9
section number title page 12.2.16 unique identification register mid low (sim_uidml) ........................................................................... 185 12.2.17 unique identification register low (sim_uidl) ...................................................................................... 186 12.2.18 cop control register (sim_copc) ........................................................................................................... 186 12.2.19 service cop register (sim_srvcop) ...................................................................................................... 187 12.3 functional description................................................................................................................................................... 188 chapter 13 system mode controller (smc) 13.1 introduction ................................................................................................................................................................... 189 13.2 modes of operation ....................................................................................................................................................... 189 13.3 memory map and register descriptions ......................................................................................................................... 191 13.3.1 power mode protection register (smc_pmprot)..................................................................................... 191 13.3.2 power mode control register (smc_pmctrl) ......................................................................................... 193 13.3.3 stop control register (smc_stopctrl) ................................................................................................. 194 13.3.4 power mode status register (smc_pmstat) ........................................................................................... 195 13.4 functional description................................................................................................................................................... 196 13.4.1 power mode transitions ................................................................................................................................ 196 13.4.2 power mode entry/exit sequencing .............................................................................................................. 199 13.4.3 run modes.................................................................................................................................................... 201 13.4.4 wait modes .................................................................................................................................................. 203 13.4.5 stop modes ................................................................................................................................................... 204 13.4.6 debug in low power modes ......................................................................................................................... 207 chapter 14 power management controller (pmc) 14.1 introduction ................................................................................................................................................................... 209 14.2 features ......................................................................................................................................................................... 209 14.3 low-voltage detect (lvd) system................................................................................................................................ 209 14.3.1 lvd reset operation ..................................................................................................................................... 210 14.3.2 lvd interrupt operation............................................................................................................................... 210 14.3.3 low-voltage warning (lvw) interrupt operation ....................................................................................... 210 kl04 sub-family reference manual, rev. 3.1, november 2012 10 freescale semiconductor, inc.
section number title page 14.4 i/o retention .................................................................................................................................................................. 211 14.5 memory map and register descriptions ......................................................................................................................... 211 14.5.1 low voltage detect status and control 1 register (pmc_lvdsc1) ........................................................ 212 14.5.2 low voltage detect status and control 2 register (pmc_lvdsc2) ........................................................ 213 14.5.3 regulator status and control register (pmc_regsc) .............................................................................. 214 chapter 15 low-leakage wakeup unit (llwu) 15.1 introduction ................................................................................................................................................................... 217 15.1.1 features ........................................................................................................................................................ 217 15.1.2 modes of operation ...................................................................................................................................... 218 15.1.3 block diagram .............................................................................................................................................. 219 15.2 llwu signal descriptions ............................................................................................................................................ 220 15.3 memory map/register definition ................................................................................................................................... 220 15.3.1 llwu pin enable 1 register (llwu_pe1) ................................................................................................ 221 15.3.2 llwu pin enable 2 register (llwu_pe2) ................................................................................................ 222 15.3.3 llwu module enable register (llwu_me) ............................................................................................ 223 15.3.4 llwu flag 1 register (llwu_f1)............................................................................................................. 225 15.3.5 llwu flag 3 register (llwu_f3)............................................................................................................. 226 15.3.6 llwu pin filter 1 register (llwu_filt1) .............................................................................................. 228 15.3.7 llwu pin filter 2 register (llwu_filt2) .............................................................................................. 229 15.4 functional description................................................................................................................................................... 230 15.4.1 lls mode ..................................................................................................................................................... 231 15.4.2 vlls modes ................................................................................................................................................ 231 15.4.3 initialization ................................................................................................................................................. 231 chapter 16 reset control module (rcm) 16.1 introduction ................................................................................................................................................................... 233 16.2 reset memory map and register descriptions ............................................................................................................... 233 16.2.1 system reset status register 0 (rcm_srs0) ............................................................................................ 233 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 11
section number title page 16.2.2 system reset status register 1 (rcm_srs1) ............................................................................................ 235 16.2.3 reset pin filter control register (rcm_rpfc) .......................................................................................... 236 16.2.4 reset pin filter width register (rcm_rpfw) ........................................................................................... 237 chapter 17 bit manipulation engine (bme) 17.1 introduction ................................................................................................................................................................... 239 17.1.1 overview ...................................................................................................................................................... 240 17.1.2 features ........................................................................................................................................................ 240 17.1.3 modes of operation ..................................................................................................................................... 241 17.2 external signal description .......................................................................................................................................... 241 17.3 memory map and register definition .......................................................................................................................... 242 17.4 functional description .................................................................................................................................................. 242 17.4.1 bme decorated stores................................................................................................................................. 242 17.4.2 bme decorated loads ................................................................................................................................. 248 17.4.3 additional details on decorated addresses and gpio accesses................................................................ 255 17.5 application information................................................................................................................................................ 256 chapter 18 miscellaneous control module (mcm) 18.1 introduction ................................................................................................................................................................... 259 18.1.1 features ........................................................................................................................................................ 259 18.2 memory map/register descriptions ............................................................................................................................... 259 18.2.1 crossbar switch (axbs) slave configuration (mcm_plasc) ................................................................ 260 18.2.2 crossbar switch (axbs) master configuration (mcm_plamc) ............................................................ 261 18.2.3 platform control register (mcm_placr) ................................................................................................ 261 18.2.4 compute operation control register (mcm_cpo) ................................................................................... 264 chapter 19 micro trace buffer (mtb) 19.1 introduction ................................................................................................................................................................... 267 19.1.1 overview ...................................................................................................................................................... 267 19.1.2 features ........................................................................................................................................................ 270 kl04 sub-family reference manual, rev. 3.1, november 2012 12 freescale semiconductor, inc.
section number title page 19.1.3 modes of operation ..................................................................................................................................... 271 19.2 external signal description .......................................................................................................................................... 271 19.3 memory map and register definition .......................................................................................................................... 272 19.3.1 mtb_ram memory map ........................................................................................................................... 272 19.3.2 mtb_dwt memory map ........................................................................................................................... 285 19.3.3 system rom memory map ......................................................................................................................... 295 chapter 20 crossbar switch lite (axbs-lite) 20.1 introduction ................................................................................................................................................................... 301 20.1.1 features ........................................................................................................................................................ 301 20.2 memory map / register definition............................................................................................................................... 301 20.3 functional description .................................................................................................................................................. 302 20.3.1 general operation ......................................................................................................................................... 302 20.3.2 arbitration .................................................................................................................................................... 303 20.4 initialization/application information ........................................................................................................................... 304 chapter 21 peripheral bridge (aips-lite) 21.1 introduction ................................................................................................................................................................... 305 21.1.1 features ........................................................................................................................................................ 305 21.1.2 general operation ......................................................................................................................................... 305 21.2 functional description................................................................................................................................................... 306 21.2.1 access support ............................................................................................................................................. 306 chapter 22 direct memory access multiplexer (dmamux) 22.1 introduction ................................................................................................................................................................... 307 22.1.1 overview ...................................................................................................................................................... 307 22.1.2 features ........................................................................................................................................................ 308 22.1.3 modes of operation ...................................................................................................................................... 308 22.2 external signal description............................................................................................................................................ 309 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 13
section number title page 22.3 memory map/register definition ................................................................................................................................... 309 22.3.1 channel configuration register (dmamux x _chcfg n ) .......................................................................... 309 22.4 functional description................................................................................................................................................... 310 22.4.1 dma channels with periodic triggering capability...................................................................................... 311 22.4.2 dma channels with no triggering capability ............................................................................................... 313 22.4.3 always-enabled dma sources .................................................................................................................... 313 22.5 initialization/application information ........................................................................................................................... 314 22.5.1 reset ............................................................................................................................................................. 314 22.5.2 enabling and configuring sources ................................................................................................................ 314 chapter 23 dma controller module 23.1 introduction ................................................................................................................................................................... 319 23.1.1 overview ...................................................................................................................................................... 319 23.1.2 features ........................................................................................................................................................ 320 23.2 dma transfer overview .............................................................................................................................................. 321 23.3 memory map and registers .......................................................................................................................................... 322 23.3.1 source address register (dma_sar n ) ..................................................................................................... 323 23.3.2 destination address register (dma_dar n ) ............................................................................................. 324 23.3.3 dma status register / byte count register (dma_dsr_bcr n ) ............................................................. 325 23.3.4 dma control register (dma_dcr n )........................................................................................................ 327 23.4 functional description .................................................................................................................................................. 331 23.4.1 transfer requests (cycle-steal and continuous modes) ............................................................................ 331 23.4.2 channel initialization and startup................................................................................................................ 331 23.4.3 dual-address data transfer mode .............................................................................................................. 333 23.4.4 advanced data transfer controls: auto-alignment ................................................................................... 334 23.4.5 termination .................................................................................................................................................. 335 kl04 sub-family reference manual, rev. 3.1, november 2012 14 freescale semiconductor, inc.
section number title page chapter 24 multipurpose clock generator (mcg) 24.1 introduction ................................................................................................................................................................... 337 24.1.1 features ........................................................................................................................................................ 337 24.1.2 modes of operation ..................................................................................................................................... 339 24.2 external signal description .......................................................................................................................................... 340 24.3 memory map/register definition................................................................................................................................. 340 24.3.1 mcg control 1 register (mcg_c1)........................................................................................................... 340 24.3.2 mcg control 2 register (mcg_c2)........................................................................................................... 342 24.3.3 mcg control 3 register (mcg_c3)........................................................................................................... 343 24.3.4 mcg control 4 register (mcg_c4)........................................................................................................... 343 24.3.5 mcg control 6 register (mcg_c6)........................................................................................................... 345 24.3.6 mcg status register (mcg_s) .................................................................................................................. 345 24.3.7 mcg status and control register (mcg_sc) ............................................................................................ 346 24.3.8 mcg auto trim compare value high register (mcg_atcvh) ............................................................ 348 24.3.9 mcg auto trim compare value low register (mcg_atcvl).............................................................. 348 24.4 functional description .................................................................................................................................................. 348 24.4.1 mcg mode state diagram ............................................................................................................................ 348 24.4.2 low power bit usage .................................................................................................................................. 352 24.4.3 mcg internal reference clocks .................................................................................................................. 352 24.4.4 external reference clock ............................................................................................................................ 353 24.4.5 mcg fixed frequency clock ....................................................................................................................... 353 24.4.6 mcg auto trim (atm) ............................................................................................................................ 353 24.5 initialization / application information ........................................................................................................................ 355 24.5.1 mcg module initialization sequence ........................................................................................................... 355 24.5.2 using a 32.768 khz reference ...................................................................................................................... 357 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 15
section number title page 24.5.3 mcg mode switching .................................................................................................................................. 358 chapter 25 oscillator (osc) 25.1 introduction ................................................................................................................................................................... 365 25.2 features and modes ...................................................................................................................................................... 365 25.3 block diagram .............................................................................................................................................................. 366 25.4 osc signal descriptions .............................................................................................................................................. 366 25.5 external crystal / resonator connections .................................................................................................................... 367 25.6 external clock connections ......................................................................................................................................... 368 25.7 memory map/register definitions ............................................................................................................................... 369 25.7.1 osc memory map/register definition ....................................................................................................... 369 25.8 functional description .................................................................................................................................................. 370 25.8.1 osc module states ...................................................................................................................................... 370 25.8.2 osc module modes..................................................................................................................................... 372 25.8.3 counter ......................................................................................................................................................... 373 25.8.4 reference clock pin requirements ............................................................................................................. 373 25.9 reset.............................................................................................................................................................................. 374 25.10 low power modes operation ....................................................................................................................................... 374 25.11 interrupts ....................................................................................................................................................................... 374 chapter 26 flash memory controller (fmc) 26.1 introduction ................................................................................................................................................................... 375 26.1.1 overview ...................................................................................................................................................... 375 26.1.2 features ........................................................................................................................................................ 375 26.2 modes of operation ....................................................................................................................................................... 376 26.3 external signal description............................................................................................................................................ 376 26.4 memory map and register descriptions ......................................................................................................................... 376 26.5 functional description................................................................................................................................................... 376 kl04 sub-family reference manual, rev. 3.1, november 2012 16 freescale semiconductor, inc.
section number title page chapter 27 flash memory module (ftfa) 27.1 introduction ................................................................................................................................................................... 379 27.1.1 features ........................................................................................................................................................ 380 27.1.2 block diagram ............................................................................................................................................. 380 27.1.3 glossary ....................................................................................................................................................... 381 27.2 external signal description .......................................................................................................................................... 382 27.3 memory map and registers .......................................................................................................................................... 382 27.3.1 flash configuration field description ......................................................................................................... 382 27.3.2 program flash ifr map ............................................................................................................................... 383 27.3.3 register descriptions ................................................................................................................................... 384 27.4 functional description .................................................................................................................................................. 392 27.4.1 flash protection............................................................................................................................................ 393 27.4.2 interrupts ...................................................................................................................................................... 393 27.4.3 flash operation in low-power modes ........................................................................................................ 394 27.4.4 functional modes of operation ................................................................................................................... 394 27.4.5 flash reads and ignored writes .................................................................................................................. 394 27.4.6 read while write (rww) ........................................................................................................................... 395 27.4.7 flash program and erase.............................................................................................................................. 395 27.4.8 flash command operations ......................................................................................................................... 395 27.4.9 margin read commands ............................................................................................................................. 400 27.4.10 flash command description ........................................................................................................................ 401 27.4.11 security ........................................................................................................................................................ 414 27.4.12 reset sequence ............................................................................................................................................ 416 chapter 28 analog-to-digital converter (adc) 28.1 introduction ................................................................................................................................................................... 417 28.1.1 features ........................................................................................................................................................ 417 28.1.2 block diagram .............................................................................................................................................. 418 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 17
section number title page 28.2 adc signal descriptions.............................................................................................................................................. 419 28.2.1 analog power (vdda) ............................................................................................................................... 420 28.2.2 analog ground (vssa) ............................................................................................................................... 420 28.2.3 voltage reference select ............................................................................................................................. 420 28.2.4 analog channel inputs (adx) ..................................................................................................................... 421 28.3 register definition......................................................................................................................................................... 421 28.3.1 adc status and control registers 1 (adc x _sc1 n ) ................................................................................... 422 28.3.2 adc configuration register 1 (adc x _cfg1) ........................................................................................... 425 28.3.3 adc configuration register 2 (adc x _cfg2) ........................................................................................... 427 28.3.4 adc data result register (adc x _r n )....................................................................................................... 428 28.3.5 compare value registers (adc x _cv n ) ..................................................................................................... 429 28.3.6 status and control register 2 (adc x _sc2) ................................................................................................ 430 28.3.7 status and control register 3 (adc x _sc3) ................................................................................................ 432 28.3.8 adc offset correction register (adc x _ofs)........................................................................................... 433 28.3.9 adc plus-side gain register (adc x _pg) ................................................................................................. 434 28.3.10 adc plus-side general calibration value register (adc x _clpd) ......................................................... 434 28.3.11 adc plus-side general calibration value register (adc x _clps) .......................................................... 435 28.3.12 adc plus-side general calibration value register (adc x _clp4) .......................................................... 435 28.3.13 adc plus-side general calibration value register (adc x _clp3) .......................................................... 436 28.3.14 adc plus-side general calibration value register (adc x _clp2) .......................................................... 436 28.3.15 adc plus-side general calibration value register (adc x _clp1) .......................................................... 437 28.3.16 adc plus-side general calibration value register (adc x _clp0) .......................................................... 437 28.4 functional description................................................................................................................................................... 438 28.4.1 clock select and divide control .................................................................................................................... 438 28.4.2 voltage reference selection .......................................................................................................................... 439 28.4.3 hardware trigger and channel selects .......................................................................................................... 439 28.4.4 conversion control ....................................................................................................................................... 440 28.4.5 automatic compare function ........................................................................................................................ 447 28.4.6 calibration function ..................................................................................................................................... 449 kl04 sub-family reference manual, rev. 3.1, november 2012 18 freescale semiconductor, inc.
section number title page 28.4.7 user-defined offset function ........................................................................................................................ 450 28.4.8 temperature sensor ...................................................................................................................................... 451 28.4.9 mcu wait mode operation ........................................................................................................................... 452 28.4.10 mcu normal stop mode operation ............................................................................................................. 452 28.4.11 mcu low-power stop mode operation ...................................................................................................... 453 28.5 initialization information .............................................................................................................................................. 454 28.5.1 adc module initialization example ............................................................................................................ 454 28.6 application information ................................................................................................................................................ 456 28.6.1 external pins and routing ............................................................................................................................. 456 28.6.2 sources of error ............................................................................................................................................ 458 chapter 29 comparator (cmp) 29.1 introduction ................................................................................................................................................................... 463 29.2 cmp features ................................................................................................................................................................ 463 29.3 6-bit dac key features ................................................................................................................................................. 464 29.4 anmux key features ................................................................................................................................................... 465 29.5 cmp, dac and anmux diagram............................................................................................................................... 465 29.6 cmp block diagram ...................................................................................................................................................... 466 29.7 memory map/register definitions.................................................................................................................................. 468 29.7.1 cmp control register 0 (cmp x _cr0) ....................................................................................................... 468 29.7.2 cmp control register 1 (cmp x _cr1) ....................................................................................................... 469 29.7.3 cmp filter period register (cmp x _fpr) ................................................................................................... 471 29.7.4 cmp status and control register (cmp x _scr) ......................................................................................... 471 29.7.5 dac control register (cmp x _daccr) .................................................................................................... 472 29.7.6 mux control register (cmp x _muxcr) .................................................................................................. 473 29.8 functional description................................................................................................................................................... 474 29.8.1 cmp functional modes................................................................................................................................. 474 29.8.2 power modes ................................................................................................................................................ 483 29.8.3 startup and operation ................................................................................................................................... 484 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 19
section number title page 29.8.4 low-pass filter ............................................................................................................................................. 484 29.9 cmp interrupts .............................................................................................................................................................. 487 29.10 dma support ................................................................................................................................................................ 487 29.11 cmp asyncrhonous dma support............................................................................................................................... 487 29.12 digital-to-analog converter ........................................................................................................................................... 488 29.13 dac functional description .......................................................................................................................................... 488 29.13.1 voltage reference source select.................................................................................................................... 488 29.14 dac resets .................................................................................................................................................................... 489 29.15 dac clocks ................................................................................................................................................................... 489 29.16 dac interrupts .............................................................................................................................................................. 489 29.17 cmp trigger mode ....................................................................................................................................................... 489 chapter 30 timer/pwm module (tpm) 30.1 introduction ................................................................................................................................................................... 491 30.1.1 tpm philosophy .......................................................................................................................................... 491 30.1.2 features ........................................................................................................................................................ 491 30.1.3 modes of operation ..................................................................................................................................... 492 30.1.4 block diagram ............................................................................................................................................. 492 30.2 tpm signal descriptions .............................................................................................................................................. 493 30.2.1 tpm_extclk tpm external clock .................................................................................................... 493 30.2.2 tpm_chn tpm channel (n) i/o pin ..................................................................................................... 494 30.3 memory map and register definition .......................................................................................................................... 494 30.3.1 status and control (tpm x _sc) ................................................................................................................... 496 30.3.2 counter (tpm x _cnt) ................................................................................................................................. 497 30.3.3 modulo (tpm x _mod) ................................................................................................................................ 498 30.3.4 channel (n) status and control (tpm x _c n sc) ........................................................................................... 499 30.3.5 channel (n) value (tpm x _c n v) ................................................................................................................. 501 30.3.6 capture and compare status (tpm x _status) ......................................................................................... 501 30.3.7 configuration (tpm x _conf) ..................................................................................................................... 503 kl04 sub-family reference manual, rev. 3.1, november 2012 20 freescale semiconductor, inc.
section number title page 30.4 functional description .................................................................................................................................................. 505 30.4.1 clock domains ............................................................................................................................................. 505 30.4.2 prescaler ....................................................................................................................................................... 506 30.4.3 counter ......................................................................................................................................................... 506 30.4.4 input capture mode ..................................................................................................................................... 508 30.4.5 output compare mode................................................................................................................................. 509 30.4.6 edge-aligned pwm (epwm) mode ........................................................................................................... 510 30.4.7 center-aligned pwm (cpwm) mode ........................................................................................................ 512 30.4.8 registers updated from write buffers ........................................................................................................ 514 30.4.9 dma ............................................................................................................................................................ 514 30.4.10 reset overview ............................................................................................................................................ 515 30.4.11 tpm interrupts ............................................................................................................................................. 515 chapter 31 periodic interrupt timer (pit-rti) 31.1 introduction ................................................................................................................................................................... 517 31.1.1 block diagram .............................................................................................................................................. 517 31.1.2 features ........................................................................................................................................................ 518 31.2 signal description.......................................................................................................................................................... 518 31.3 memory map/register description ................................................................................................................................. 519 31.3.1 pit module control register (pit_mcr) .................................................................................................. 519 31.3.2 pit upper lifetime timer register (pit_ltmr64h) ............................................................................... 521 31.3.3 pit lower lifetime timer register (pit_ltmr64l) ............................................................................... 521 31.3.4 timer load value register (pit_ldval n )............................................................................................... 522 31.3.5 current timer value register (pit_cval n ) ............................................................................................. 522 31.3.6 timer control register (pit_tctrl n ) ...................................................................................................... 523 31.3.7 timer flag register (pit_tflg n ) .............................................................................................................. 524 31.4 functional description................................................................................................................................................... 524 31.4.1 general operation ......................................................................................................................................... 524 31.4.2 interrupts ...................................................................................................................................................... 526 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 21
section number title page 31.4.3 chained timers ............................................................................................................................................. 526 31.5 initialization and application information..................................................................................................................... 526 31.6 example configuration for chained timers.................................................................................................................... 527 31.7 example configuration for the lifetime timer ............................................................................................................... 528 chapter 32 low-power timer (lptmr) 32.1 introduction ................................................................................................................................................................... 531 32.1.1 features ........................................................................................................................................................ 531 32.1.2 modes of operation ...................................................................................................................................... 531 32.2 lptmr signal descriptions .......................................................................................................................................... 532 32.2.1 detailed signal descriptions ......................................................................................................................... 532 32.3 memory map and register definition............................................................................................................................. 532 32.3.1 low power timer control status register (lptmr x _csr) ...................................................................... 533 32.3.2 low power timer prescale register (lptmr x _psr) ................................................................................ 534 32.3.3 low power timer compare register (lptmr x _cmr) ............................................................................. 536 32.3.4 low power timer counter register (lptmr x _cnr) ............................................................................... 536 32.4 functional description................................................................................................................................................... 537 32.4.1 lptmr power and reset .............................................................................................................................. 537 32.4.2 lptmr clocking.......................................................................................................................................... 537 32.4.3 lptmr prescaler/glitch filter ...................................................................................................................... 537 32.4.4 lptmr compare.......................................................................................................................................... 539 32.4.5 lptmr counter ........................................................................................................................................... 539 32.4.6 lptmr hardware trigger ............................................................................................................................. 540 32.4.7 lptmr interrupt.......................................................................................................................................... 540 chapter 33 real time clock (rtc) 33.1 introduction ................................................................................................................................................................... 541 33.1.1 features ........................................................................................................................................................ 541 33.1.2 modes of operation ...................................................................................................................................... 541 kl04 sub-family reference manual, rev. 3.1, november 2012 22 freescale semiconductor, inc.
section number title page 33.1.3 rtc signal descriptions ............................................................................................................................. 541 33.2 register definition......................................................................................................................................................... 542 33.2.1 rtc time seconds register (rtc_tsr) ................................................................................................... 543 33.2.2 rtc time prescaler register (rtc_tpr) .................................................................................................. 543 33.2.3 rtc time alarm register (rtc_tar) ..................................................................................................... 544 33.2.4 rtc time compensation register (rtc_tcr) ......................................................................................... 544 33.2.5 rtc control register (rtc_cr)................................................................................................................ 545 33.2.6 rtc status register (rtc_sr) .................................................................................................................. 547 33.2.7 rtc lock register (rtc_lr) .................................................................................................................... 548 33.2.8 rtc interrupt enable register (rtc_ier)................................................................................................. 549 33.3 functional description................................................................................................................................................... 550 33.3.1 power, clocking, and reset ........................................................................................................................... 550 33.3.2 time counter ................................................................................................................................................ 551 33.3.3 compensation............................................................................................................................................... 551 33.3.4 time alarm ................................................................................................................................................... 552 33.3.5 update mode ................................................................................................................................................ 552 33.3.6 register lock ................................................................................................................................................ 553 33.3.7 interrupt ........................................................................................................................................................ 553 chapter 34 serial peripheral interface (spi) 34.1 introduction ................................................................................................................................................................... 555 34.1.1 features ........................................................................................................................................................ 555 34.1.2 modes of operation ..................................................................................................................................... 556 34.1.3 block diagrams............................................................................................................................................ 557 34.2 external signal description .......................................................................................................................................... 559 34.2.1 spsck spi serial clock ......................................................................................................................... 559 34.2.2 mosi master data out, slave data in ................................................................................................... 560 34.2.3 miso master data in, slave data out ................................................................................................... 560 34.2.4 ss slave select........................................................................................................................................ 560 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 23
section number title page 34.3 memory map and register descriptions ...................................................................................................................... 561 34.3.1 spi control register 1 (spi x _c1) .................................................................................................................. 561 34.3.2 spi control register 2 (spi x _c2) .................................................................................................................. 563 34.3.3 spi baud rate register (spi x _br)................................................................................................................. 564 34.3.4 spi status register (spi x _s) ......................................................................................................................... 565 34.3.5 spi data register (spi x _d) ........................................................................................................................... 566 34.3.6 spi match register (spi x _m) ....................................................................................................................... 567 34.4 functional description .................................................................................................................................................. 568 34.4.1 general ......................................................................................................................................................... 568 34.4.2 master mode ................................................................................................................................................ 568 34.4.3 slave mode .................................................................................................................................................. 570 34.4.4 spi transmission by dma .......................................................................................................................... 571 34.4.5 spi clock formats ....................................................................................................................................... 573 34.4.6 spi baud rate generation ........................................................................................................................... 576 34.4.7 special features ........................................................................................................................................... 576 34.4.8 error conditions ........................................................................................................................................... 578 34.4.9 low power mode options ........................................................................................................................... 579 34.4.10 reset ............................................................................................................................................................. 580 34.4.11 interrupts ...................................................................................................................................................... 581 34.5 initialization/application information .......................................................................................................................... 582 34.5.1 initialization sequence ................................................................................................................................. 582 34.5.2 pseudo-code example ................................................................................................................................. 583 chapter 35 inter-integrated circuit (i2c) 35.1 introduction ................................................................................................................................................................... 587 35.1.1 features ........................................................................................................................................................ 587 35.1.2 modes of operation ...................................................................................................................................... 588 35.1.3 block diagram .............................................................................................................................................. 588 35.2 i2c signal descriptions.................................................................................................................................................. 589 kl04 sub-family reference manual, rev. 3.1, november 2012 24 freescale semiconductor, inc.
section number title page 35.3 memory map and register descriptions ......................................................................................................................... 589 35.3.1 i2c address register 1 (i2c x _a1) .............................................................................................................. 590 35.3.2 i2c frequency divider register (i2c x _f) .................................................................................................... 591 35.3.3 i2c control register 1 (i2c x _c1) ............................................................................................................... 592 35.3.4 i2c status register (i2c x _s) ........................................................................................................................ 593 35.3.5 i2c data i/o register (i2c x _d) ................................................................................................................... 595 35.3.6 i2c control register 2 (i2c x _c2) ............................................................................................................... 596 35.3.7 i2c programmable input glitch filter register (i2c x _flt) ....................................................................... 597 35.3.8 i2c range address register (i2c x _ra) ...................................................................................................... 598 35.3.9 i2c smbus control and status register (i2c x _smb) ................................................................................. 599 35.3.10 i2c address register 2 (i2c x _a2) .............................................................................................................. 600 35.3.11 i2c scl low timeout register high (i2c x _slth) .................................................................................. 601 35.3.12 i2c scl low timeout register low (i2c x _sltl) ................................................................................... 601 35.4 functional description................................................................................................................................................... 601 35.4.1 i2c protocol ................................................................................................................................................. 601 35.4.2 10-bit address ............................................................................................................................................... 607 35.4.3 address matching ......................................................................................................................................... 608 35.4.4 system management bus specification ........................................................................................................ 609 35.4.5 resets ........................................................................................................................................................... 612 35.4.6 interrupts ...................................................................................................................................................... 612 35.4.7 programmable input glitch filter .................................................................................................................. 614 35.4.8 address matching wakeup ........................................................................................................................... 615 35.4.9 dma support ............................................................................................................................................... 615 35.5 initialization/application information ........................................................................................................................... 616 chapter 36 universal asynchronous receiver/transmitter (uart0) 36.1 introduction ................................................................................................................................................................... 619 36.1.1 features ........................................................................................................................................................ 619 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 25
section number title page 36.1.2 modes of operation ...................................................................................................................................... 620 36.1.3 block diagram .............................................................................................................................................. 620 36.2 register definition......................................................................................................................................................... 622 36.2.1 uart baud rate register high (uart x _bdh) ....................................................................................... 623 36.2.2 uart baud rate register low (uart x _bdl) ........................................................................................ 624 36.2.3 uart control register 1 (uart x _c1) ..................................................................................................... 624 36.2.4 uart control register 2 (uart x _c2) ..................................................................................................... 626 36.2.5 uart status register 1 (uart x _s1) ........................................................................................................ 627 36.2.6 uart status register 2 (uart x _s2) ........................................................................................................ 629 36.2.7 uart control register 3 (uart x _c3) ..................................................................................................... 631 36.2.8 uart data register (uart x _d) ............................................................................................................... 632 36.2.9 uart match address registers 1 (uart x _ma1) .................................................................................... 633 36.2.10 uart match address registers 2 (uart x _ma2) .................................................................................... 634 36.2.11 uart control register 4 (uart x _c4) ..................................................................................................... 634 36.2.12 uart control register 5 (uart x _c5) ..................................................................................................... 635 36.3 functional description................................................................................................................................................... 636 36.3.1 baud rate generation .................................................................................................................................... 636 36.3.2 transmitter functional description ............................................................................................................... 636 36.3.3 receiver functional description ................................................................................................................... 638 36.3.4 additional uart functions ......................................................................................................................... 641 36.3.5 interrupts and status flags ............................................................................................................................ 643 chapter 37 general-purpose input/output (gpio) 37.1 introduction ................................................................................................................................................................... 645 37.1.1 features ........................................................................................................................................................ 645 37.1.2 modes of operation ...................................................................................................................................... 645 37.1.3 gpio signal descriptions ............................................................................................................................. 646 37.2 memory map and register definition............................................................................................................................. 647 37.2.1 port data output register (gpio x _pdor)................................................................................................. 648 kl04 sub-family reference manual, rev. 3.1, november 2012 26 freescale semiconductor, inc.
section number title page 37.2.2 port set output register (gpio x _psor) .................................................................................................... 649 37.2.3 port clear output register (gpio x _pcor) ................................................................................................ 649 37.2.4 port toggle output register (gpio x _ptor) ............................................................................................. 650 37.2.5 port data input register (gpio x _pdir) ..................................................................................................... 650 37.2.6 port data direction register (gpio x _pddr)............................................................................................. 651 37.3 fgpio memory map and register definition ................................................................................................................ 651 37.3.1 port data output register (fgpio x _pdor) .............................................................................................. 652 37.3.2 port set output register (fgpio x _psor) ................................................................................................. 652 37.3.3 port clear output register (fgpio x _pcor) ............................................................................................. 653 37.3.4 port toggle output register (fgpio x _ptor) ........................................................................................... 653 37.3.5 port data input register (fgpio x _pdir)................................................................................................... 654 37.3.6 port data direction register (fgpio x _pddr) .......................................................................................... 654 37.4 functional description................................................................................................................................................... 655 37.4.1 general-purpose input .................................................................................................................................. 655 37.4.2 general-purpose output ................................................................................................................................ 655 37.4.3 ioport ....................................................................................................................................................... 655 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 27
kl04 sub-family reference manual, rev. 3.1, november 2012 28 freescale semiconductor, inc.
chapter 1 about this document overview 1.1.1 purpose this document describes the features, architecture, and programming model of the freescale kl04 microcontroller. 1.1.2 audience this document is primarily for system architects and software application developers who are using or considering using the kl04kl02 microcontroller in a system. conventions 1.2.1 numbering systems the following suffixes identify different numbering systems: this suffix identifies a b binary number. for example, the binary equivalent of the number 5 is written 101b. in some cases, binary numbers are shown with the prefix 0b . d decimal number. decimal numbers are followed by this suffix only when the possibility of confusion exists. in general, decimal numbers are shown without a suffix. h hexadecimal number. for example, the hexadecimal equivalent of the number 60 is written 3ch. in some cases, hexadecimal numbers are shown with the prefix 0x . 1.1 1.2 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 29
1.2.2 typographic notation the following typographic notation is used throughout this document: example description placeholder , x items in italics are placeholders for information that you provide. italicized text is also used for the titles of publications and for emphasis. plain lowercase letters are also used as placeholders for single letters and numbers. code fixed-width type indicates text that must be typed exactly as shown. it is used for instruction mnemonics, directives, symbols, subcommands, parameters, and operators. fixed-width type is also used for example code. instruction mnemonics and directives in text and tables are shown in all caps; for example, bsr. sr[scm] a mnemonic in brackets represents a named field in a register. this example refers to the scaling mode (scm) field in the status register (sr). revno[6:4], xad[7:0] numbers in brackets and separated by a colon represent either: ? a subset of a register's named field for example, revno[6:4] refers to bits 6C4 that are part of the corerev field that occupies bits 6C0 of the revno register. ? a continuous range of individual signals of a bus for example, xad[7:0] refers to signals 7C0 of the xad bus. 1.2.3 special terms the following terms have special meanings: term meaning asserted refers to the state of a signal as follows: ? an active-high signal is asserted when high (1). ? an active-low signal is asserted when low (0). deasserted refers to the state of a signal as follows: ? an active-high signal is deasserted when low (0). ? an active-low signal is deasserted when high (1). in some cases, deasserted signals are described as negated . reserved refers to a memory space, register, or field that is either reserved for future use or for which, when written to, the module or chip behavior is unpredictable. conventions kl04 sub-family reference manual, rev. 3.1, november 2012 30 freescale semiconductor, inc.
chapter 2 introduction 2.1 overview this chapter provides an overview of the kinetis l series of arm? cortex?-m0+ mcus and kl04 product family. it also presents high-level descriptions of the modules available on the devices covered by this document. 2.2 kinetis l series the kinetis l series is the most scalable portfolio of ultra low-power, mixed-signal arm cortex-m0+ mcus in the industry. the portfolio includes 5 mcu families that offer a broad range of memory, peripheral and package options. kinetis l series families share common peripherals and pin-counts allowing developers to migrate easily within an mcu family or between mcu families to take advantage of more memory or feature integration. this scalability allows developers to standardize on the kinetis l series for their end product platforms, maximising hardware and software reuse and reducing time- to-market. features common to all kinetis l series families include: ? 48 mhz arm cortex-m0+ core ? high-speed 12/16-bit analog-to-digital converters ? 12-bit digital-to-analog converters for all series except for klx4/klx2 family ? high-speed analog comparators ? low-power touch sensing with wake-up on touch from reduced power states for all series except for klx4/klx2 family ? powerful timers for a broad range of applications including motor control ? low power focused serial communication interfaces such as low power uart, spi, i2c etc. ? single power supply: 1.71v - 3.6v with multiple low-power modes support single operation temperature: -40 ~ 105 c (exclude csp package) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 31
kinetis l series mcu families combine the latest low-power innovations with precision mixed-signal capability and a broad range of communication, connectivity, and human- machine interface peripherals. each mcu family is supported by a market-leading enablement bundle from freescale and numerous arm 3rd party ecosystem partners. the kl0x family is the entry-point to the kinetis l series and is pin compatible with the 8-bit s08pt family. the kl1x/2x/3x/4x families are compatible with each other and their equivalent arm cortex-m4 kinetis k series families - k10/20/30/40. kl2x family kl1x family kl0x family kl3x family family program flash packages key features low power mixed signal usb segment lcd kl4x family 8-32kb 32-256kb 32-256kb 64-256kb 128-256kb 16-48pin 32-80pin 32-121pin 64-121pin 64-121pin figure 2-1. kinetis l series families of mcu portfolio all kinetis l series families include a powerful array of analog, communication and timing and control peripherals with the level of feature integration increasing with flash memory size and the pin count. features within the kinetis l series families include: ? core and architecture: ? arm cortex-m0+ core running up to 48 mhz with zero wait state execution from memories ? single-cycle access to i/o: up to 50 percent faster than standard i/o, improves reaction time to external events allowing bit banging and software protocol emulation ? two-stage pipeline: reduced number of cycles per instruction (cpi), enabling faster branch instruction and isr entry, and reducing power consumption ? excellent code density vs. 8-bit and 16-bit mcus - reduces flash size, system cost and power consumption kinetis l series kl04 sub-family reference manual, rev. 3.1, november 2012 32 freescale semiconductor, inc.
? optimized access to program memory: accesses on alternate cycles reduces power consumption ? 100 percent compatible with arm cortex-m0 and a subset arm cortex- m3/m4: reuse existing compilers and debug tools ? simplified architecture: 56 instructions and 17 registers enables easy programming and efficient packaging of 8/16/32-bit data in memory ? linear 4 gb address space removes the need for paging/banking, reducing software complexity ? arm third-party ecosystem support: software and tools to help minimize development time/cost ? micro trace buffer: lightweight trace solution allows fast bug identification and correction ? bme: bit manipulation engine reduces code size and cycles for bit oriented operations to peripheral registers eliminating traditional methods where the core would need to perform read-modify-write operations. ? up to 4-channel dma for peripheral and memory servicing with minimal cpu intervention (feature not available on kl02 family) ? ultra low-power: ? extreme dynamic efficiency: 32-bit arm cortex-m0+ core combined with freescale 90 nm thin film storage flash technology delivers 50% energy savings per coremark versus the closest 8/16-bit competitive solution ? multiple flexible low-power modes, including new operation clocking option which reduces dynamic power by shutting off bus and system clocks for lowest power core processing. peripherals with an alternate asynchronous clock source can continue operation. ? uart, spi, i2c, adc, dac, tpm, lpt, and dma support low-power mode operation without waking up the core ? memory: ? scalable memory footprints from 8 kb flash / 1 kb sram to 256 kb flash / 32 kb sram ? embedded 64 b cache memory for optimizing bus bandwidth and flash execution performance (32 b cache on kl02 family) ? mixed-signal analog: ? fast, high precision 16-, or 12-bit adc with optional differential pairs, 12-bit dac, high speed comparators. powerful signal conditioning, conversion and analysis capability with reduced system cost (12-bit dac not available on kl02 family) ? human machine interface (hmi): ? optional capacitive touch sensing interface with full low-power support and minimal current adder when enabled ? segment lcd controller chapter 2 introduction kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 33
? connectivity and communications: ? up to three uarts, all uarts support dma transfers, and can trigger when data on bus is detected, uart0 supports 4x to 32x over sampling ratio. asynchronous transmit and receive operation for operating in stop/vlps modes. ? up to two spis ? up to two i 2 cs ? full-speed usb otg controller with on-chip transceiver ? 5 v to 3.3 v usb on-chip regulator ? up to one i 2 s ? reliability, safety and security: ? internal watchdog with independent clock source ? timing and control: ? powerful timer modules which support general purpose, pwm, and motor control functions ? periodic interrupt timer for rtos task scheduler time base or trigger source for adc conversion and timer modules ? system: ? gpio with pin interrupt functionality ? wide operating voltage range from 1.71 v to 3.6 v with flash programmable down to 1.71 v with fully functional flash and analog peripherals ? ambient operating temperature ranges from -40 c to 105 c 2.3 kl04 sub-family introduction the device is highly-integrated, market leading ultra low power 32-bit microcontroller based on the enhanced cortex-m0+ (cm0+) core platform. the family derivatives feature: ? core platform clock up to 48 mhz, bus clock up to 24 mhz ? memory option is up to 32 kb flash and 4 kb ram ? wide operating voltage ranges from 1.71v to 3.6v with full functional flash program/erase/read operations ? multiple package options from 24-pin to 48-pin ? ambient operating temperature ranges from C40 c to 105 c the family acts as an ultra low power, cost effective microcontroller to provide developers an appropriate entry-level 32-bit solution. the family is next generation mcu solution for low cost, low power, high performance devices applications. its valuable for cost-sensitive, portable applications requiring long battery life-time. kl04 sub-family introduction kl04 sub-family reference manual, rev. 3.1, november 2012 34 freescale semiconductor, inc.
2.4 module functional categories the modules on this device are grouped into functional categories. the following sections describe the modules assigned to each category in more detail. table 2-1. module functional categories module category description arm cortex-m0+ core ? 32-bit mcu core from arms cortex-m class, 1.77 coremark ? /mhz from single-cycle access memories, 48 mhz cpu frequency system ? system integration module ? power management and mode controllers ? multiple power modes available based on run, wait, stop, and power- down modes ? miscellaneous control module ? low-leakage wakeup unit ? peripheral bridge ? direct memory access (dma) controller with multiplexer to increase available dma requests ? cop watchdog memories ? internal memories include: ? up to 32 kb flash memory ? up to 4 kb sram clocks ? multiple clock generation options available from internally- and externally- generated clocks ? mcg module with fll for systems and cpu clock sources ? low power 1 khz rc oscillator for rtc and cop watchdog ? system oscillator to provide clock source for the mcu security ? cop watchdog timer (cop) analog ? 12-bit analog-to-digital converters with dma supported ? comparator (cmp) with internal 6-bit digital-to-analog converter (dac) timers ? one 6-channel tpm ? one 2-channel tpm ? 2-channel periodic interrupt timer ? real time clock ? low-power timer ? system tick timer communications ? one8-bit serial peripheral interface ? one inter-integrated circuit (i 2 c) module ? one low power uart module human-machine interfaces (hmi) ? general purpose input/output controller 2.4.1 arm? cortex?-m0+ core modules the following core modules are available on this device. chapter 2 introduction kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 35
table 2-2. core modules module description arm? cortex?-m0+ the arm? cortex?-m0+ is the newest member of the cortex m series of processors targeting microcontroller applications focused on very cost sensitive, deterministic, interrupt driven environments. the cortex m0+ processor is based on the armv6 architecture and thumb?-2 isa and is 100% instruction set compatible with its predecessor, the cortex-m0 core, and upward compatible to cortex-m3 and m4 cores. nvic the armv6-m exception model and nested-vectored interrupt controller (nvic) implement a relocatable vector table supporting many external interrupts, a single non-maskable interrupt (nmi), and priority levels. the nvic replaces shadow registers with equivalent system and simplified programmability. the nvic contains the address of the function to execute for a particular handler. the address is fetched via the instruction port allowing parallel register stacking and look-up. the first sixteen entries are allocated to arm internal sources with the others mapping to mcu-defined interrupts. awic the primary function of the asynchronous wake-up interrupt controller (awic) is to detect asynchronous wake-up events in stop modes and signal to clock control logic to resume system clocking. after clock restart, the nvic observes the pending interrupt and performs the normal interrupt or event processing. single-cycle i/o port for high-speed, single-cycle access to peripherals, the cortex-m0+ processor implements a dedicated single-cycle i/o port. debug interfaces most of this device's debug is based on the arm coresight ? architecture. one debug interface is supported: ? serial wire debug (swd) 2.4.2 system modules the following system modules are available on this device. table 2-3. system modules module description system integration module (sim) the sim includes integration logic and several module configuration settings. system mode controller the smc provides control and protection on entry and exit to each power mode, control for the power management controller (pmc), and reset entry and exit for the complete mcu. power management controller (pmc) the pmc provides the user with multiple power options. multiple modes are supported that allow the user to optimize power consumption for the level of functionality needed. includes power-on-reset (por) and integrated low voltage detect (lvd) with reset (brownout) capability and selectable lvd trip points. miscellaneous control module (mcm) the mcm includes integration logic and details. crossbar switch (xbs) the xbs connects bus masters and bus slaves, allowing all bus masters to access different bus slaves simultaneously and providing arbitration among the bus masters when they access the same slave. low-leakage wakeup unit (llwu) the llwu module allows the device to wake from low leakage power modes (lls and vlls) through various internal peripheral and external pin sources. table continues on the next page... module functional categories kl04 sub-family reference manual, rev. 3.1, november 2012 36 freescale semiconductor, inc.
table 2-3. system modules (continued) module description peripheral bridge the peripheral bridge converts the crossbar switch interface to an interface to access a majority of peripherals on the device. dma multiplexer (dmamux) the dma multiplexer selects from many dma requests down to 4 for the dma controller. direct memory access (dma) controller the dma controller provides programmable channels with transfer control descriptors for data movement via dual-address transfers for 8-, 16- and 32-bit data values. computer operating properly watchdog (wdog) the wdog monitors internal system operation and forces a reset in case of failure. it can run from an independent 1 khz low power oscillator with a programmable refresh window to detect deviations in program flow or system frequency. 2.4.3 memories and memory interfaces the following memories and memory interfaces are available on this device. table 2-4. memories and memory interfaces module description flash memory program flash memory up to 32 kb of the non-volatile flash memory that can execute program code flash memory controller manages the interface between the device and the on-chip flash memory. sram up to 4 kb internal system ram. 2.4.4 clocks the following clock modules are available on this device. table 2-5. clock modules module description multipurpose clock generator (mcg) mcg module containing a frequency-locked-loop (fll) controlled by internal or external reference oscillator. system oscillator the system oscillator, in conjunction with an external crystal or resonator, generates a reference clock for the mcu. 2.4.5 security and integrity modules the following security and integrity modules are available on this device: chapter 2 introduction kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 37
table 2-6. security and integrity modules module description watchdog timer (wdog) watchdog timer keeps a watch on the system functioning and resets it in case of its failure. 2.4.6 analog modules the following analog modules are available on this device: table 2-7. analog modules module description analog-to-digital converters (adc) 12-bit successive-approximation adc module. analog comparators one comparator that compares two analog input voltages across the full range of the supply voltage and can trigger an adc acquisition, tpm update, or cpu interrupt. 6-bit digital-to-analog converters (dac) 64-tap resistor ladder network which provides a selectable voltage reference for comparator. 2.4.7 timer modules the following timer modules are available on this device: table 2-8. timer modules module description timer/pwm module (tpm) ? selectable tpm clock mode ? prescaler divide-by 1, 2, 4, 8, 16, 32, 64, or 128 ? 16-bit free-running counter or modulo counter with counting be up or up- down ? six configurable channels for input capture, output compare, or edge-aligned pwm mode ? support the generation of an interrupt and/or dma request per channel ? support the generation of an interrupt and/or dma request when the counter overflows ? support selectable trigger input to optionally reset or cause the counter to start incrementing. ? support the generation of hardware triggers when the counter overflows and per channel periodic interrupt timers (pit) ? one general purpose interrupt timer ? interrupt timers for triggering adc conversions ? 32-bit counter resolution ? clocked by bus clock frequency ? dma support table continues on the next page... module functional categories kl04 sub-family reference manual, rev. 3.1, november 2012 38 freescale semiconductor, inc.
table 2-8. timer modules (continued) module description low power timer (lptmr) ? 16-bit time counter or pulse counter with compare ? configurable clock source for prescaler/glitch filter ? configurable input source for pulse counter real-time counter (rtc) ? 16-bit up-counter ? 16-bit modulo match limit ? software controllable periodic interrupt on match ? software selectable clock sources for input to prescaler with programmable 16-bit prescaler ? xosc 32.678 khz nominal ? lpo (~1 khz) ? external rtc_clkin 2.4.8 communication interfaces the following communication interfaces are available on this device: table 2-9. communication modules module description serial peripheral interface (spi) synchronous serial bus for communication to an external device inter-integrated circuit (i2c) allows communication between a number of devices. also supports the system management bus (smbus) specification, version 2. universal asynchronous receiver/ transmitters (uart) one low power uart module that retains functional in stop modes. 2.4.9 human-machine interfaces the following human-machine interfaces (hmi) are available on this device: table 2-10. hmi modules module description general purpose input/output (gpio) some general purpose input or output (gpio) pins are capable of interrupt and dma request generation. 2.5 orderable part numbers the following table summarizes the part numbers of the devices covered by this document. chapter 2 introduction kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 39
table 2-11. orderable part numbers summary freescale part number cpu frequency pin count package total flash memory ram temperature range mkl04z8vfk4 48 mhz 24 qfn 8 kb 1 kb -40 to 105 c mkl04z16vfk4 48 mhz 24 qfn 16 kb 2 kb -40 to 105 c mkl04z32vfk4 48 mhz 24 qfn 32 kb 4 kb -40 to 105 c mkl04z8vlc4 48 mhz 32 lqfp 8 kb 1 kb -40 to 105 c mkl04z16vlc4 48 mhz 32 lqfp 16 kb 2 kb -40 to 105 c mkl04z32vlc4 48 mhz 32 lqfp 32 kb 4 kb -40 to 105 c mkl04z8vfm4 48 mhz 32 qfn 8 kb 1 kb -40 to 105 c MKL04Z16VFM4 48 mhz 32 qfn 16 kb 2 kb -40 to 105 c mkl04z32vfm4 48 mhz 32 qfn 32 kb 4 kb -40 to 105 c mkl04z16vlf4 48 mhz 48 lqfp 16 kb 2 kb -40 to 105 c mkl04z32vlf4 48 mhz 48 lqfp 32 kb 4 kb -40 to 105 c orderable part numbers kl04 sub-family reference manual, rev. 3.1, november 2012 40 freescale semiconductor, inc.
chapter 3 chip configuration 3.1 introduction this chapter provides details on the individual modules of the microcontroller. it includes: ? module block diagrams showing immediate connections within the device ? specific module-to-module interactions not necessarily discussed in the individual module chapters ? links for more information module to module interconnects 3.2.1 module to module interconnects the below table captures the module to module interconnections for this device. table 3-1. module to module interconnects peripheral signal to peripheral use case control comment tpm1 ch0f, ch1f to adc (trigger) adc triggering (a and b) sopt7_adcal ttrgen = 0 ch0 is a, and ch1 is b, selecting this adc trigger is for supporting a and b triggering. in stop and vlps modes, the second trigger must be set to >10us after the first trigger table continues on the next page... 3.2 kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 41
table 3-1. module to module interconnects (continued) peripheral signal to peripheral use case control comment lptmr hardware trigger to adc (trigger) adc triggering (a or b) sopt7_adc0t rgsel (4 bit field), adc0pretrg sel to select a or b tpmx tof to adc (trigger) adc triggering (a or b) sopt7_adc0t rgsel (4 bit field), sopt7_adc0p retrgsel to select a or b pit chx tif0, tif1 to adc (trigger) adc triggering (a or b) sopt7_adc0t rgsel (4 bit field), adc0pretrg sel to select a or b rtc alarm or seconds to adc (trigger) adc triggering (a or b) sopt7_adc0t rgsel (4 bit field) adc0pretrg sel to select a or b extrg_in extrg_in to adc (trigger) adc triggering (a or b) sopt7_adc0t rgsel (4 bit field) adc0pretrg sel to select a or b cmp0 cmp0_out to adc (trigger) adc triggering (aor b) sopt7_adc0t rgsel (4 bit field) adc0pretrg sel to select a or b cmp0 cmp0_out to lptmr_alt0 count cmp events lptmr_csr[t ps] cmp0 cmp0_out to tpm1 ch0 input capture sopt4_tpm1c h0src cmp0 cmp0_out to uart0_rx ir interface sopt5_uart0 rxsrc lptmr hardware trigger to cmpx low power triggering of the comparator cmp_cr1[trig m] lptmr hardware trigger to tpmx tpm trigger input tpmx_conf[t rgsel] (4 bit field) tpmx tof to tpmx tpm trigger input tpmx_conf[t rgsel] (4 bit field) table continues on the next page... module to module interconnects kl04 sub-family reference manual, rev. 3.1, november 2012 42 freescale semiconductor, inc.
table 3-1. module to module interconnects (continued) peripheral signal to peripheral use case control comment tpm1 timebase to tpmx tpm global timebase input tpmx_conf[g tbeen] pit chx tif0, tif1 to tpmx tpm trigger input tpmx_conf[t rgsel] (4 bit field) if pit is triggering the tpm, the tpm clock must be faster than bus clock. rtc alarm or seconds to tpmx tpm trigger input tpmx_conf[t rgsel] (4 bit field) extrg_in extrg_in to tpmx tpm trigger input tpmx_conf[t rgsel] (4 bit field) cmp0 cmp0_out to tpmx tpm trigger input tpmx_conf[t rgsel] (4 bit field) uart0 uart0_tx to modulated by tpm1 ch0 uart modulation sopt5_uart0 txsrc pit tif0 to dac advance dac fifo dac hwtrg select pit tif0 to dma ch0 dma hw trigger dma mux register option pit tif1 to dma ch1 dma hw trigger dma mux register option 3.2.2 analog reference options several analog blocks have selectable reference voltages as shown in the below table. these options allow analog peripherals to share or have separate analog references. care should be taken when selecting analog references to avoid cross talk noise. table 3-2. analog reference options module reference option comment/ reference selection 12-bit sar adc 1 - vrefh 2 - vdda 3 - reserved selected by adcx_sc2[refsel] bits cmp with 6-bit dac vin1 - vrefh vin2 - vdd 1 selected by cmpx_daccr[vrsel] bit 1. use this option for the best adc operation. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 43
core modules 3.3.1 arm cortex-m0+ core configuration this section summarizes how the module has been configured in the chip. full documentation for this module is provided by arm and can be found at www.arm.com . arm cortex-m0+ core debug interrupts crossbar switch figure 3-1. core configuration table 3-3. reference links to related information topic related module reference full description arm cortex-m0+ core, r0p0 arm cortex-m0+ technical reference manual, r0p0 system memory map system memory map clocking clock distribution power management power management system/instruction/data bus module crossbar switch crossbar switch debug serial wire debug (swd) debug interrupts nested vectored interrupt controller (nvic) nvic miscellaneous control module (mcm) mcm 3.3.1.1 arm cortex m0+ core the arm cortex m0+ parameter settings are as follows: 3.3 core modules kl04 sub-family reference manual, rev. 3.1, november 2012 44 freescale semiconductor, inc.
table 3-4. arm cortex-m0+ parameter settings parameter verilog name value description arch clock gating acg 1 = present implements architectural clock gating dap slave port support ahbslv 1 support any ahb debug access port (like the cm4 dap) dap rom table base baseaddr 0xf000_2003 base address for dap rom table endianess be 0 little endian control for data transfers breakpoints bkpt 2 implements 2 breakpoints debug support dbg 1 = present halt event support haltev 1 = present i/o port iop 1 = present implements single-cycle ld/st accesses to special address space irq mask enable irqdis 0x00000000 assume (for now) all 32 irqs are used (set if irq is disabled) debug port protocol jtagnsw 0 = swd swd protocol, not jtag core memory protection mpu 0 = absent no mpu number of irqs numirq 32 assume full nvic request vector reset all regs rar 0 = standard do not force all registers to be async reset multiplier smul 0 = fast mul implements single-cycle multiplier multi-drop support swmd 0 = absent do not include serial wire support for multi- drop system tick timer syst 1 = present implements system tick timer (for cm4 compatibility) dap target id targetid 0 user/privileged user 1 = present implements processor operating modes vector table offset register vtor 1 = present implements relocation of exception vector table wic support wic 1 = present implements wic interface wic requests wiclines 34 exact number of wakeup irqs is 34 watchpoints wpt 2 implements 2 watchpoints for details on the arm cortex-m0+ processor core, see the arm website: www.arm.com. 3.3.1.2 buses, interconnects, and interfaces the arm cortex-m0+ core has two bus interfaces: ? single 32-bit amba-3 ahb-lite system interface that provides connections to peripherals and all system memory, which includes flash and ram. ? single 32-bit i/o port bus interfacing to the gpio with 1-cycle loads and stores. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 45
3.3.1.3 system tick timer the clksource bit in systick control and status register selects either the core clock (when clksource = 1) or a divide-by-16 of the core clock (when clksource = 0). because the timing reference is a variable frequency, the tenms bit in the systick calibration value register is always zero. 3.3.1.4 debug facilities this device supports standard arm 2-pin swd debug port. 3.3.1.5 core privilege levels the core on this device is implemented with both privileged and unprivileged levels. the arm documentation uses different terms than this document to distinguish between privilege levels. if you see this term... it also means this term... privileged supervisor unprivileged or user user 3.3.2 nested vectored interrupt controller (nvic) configuration this section summarizes how the module has been configured in the chip. full documentation for this module is provided by arm and can be found at www.arm.com . nested vectored interrupt controller (nvic) arm cortex-m0+ core interrupts module module module ppb figure 3-2. nvic configuration table 3-5. reference links to related information topic related module reference full description nested vectored interrupt controller (nvic) arm cortex-m0+ technical reference manual system memory map system memory map clocking clock distribution table continues on the next page... core modules kl04 sub-family reference manual, rev. 3.1, november 2012 46 freescale semiconductor, inc.
table 3-5. reference links to related information (continued) topic related module reference power management power management private peripheral bus (ppb) arm cortex-m0+ core arm cortex-m0+ core 3.3.2.1 interrupt priority levels this device supports 4 priority levels for interrupts. therefore, in the nvic each source in the ipr registers contains 2 bits. for example, ipr0 is shown below: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r irq3 0 0 0 0 0 0 irq2 0 0 0 0 0 0 irq1 0 0 0 0 0 0 irq0 0 0 0 0 0 0 w 3.3.2.2 non-maskable interrupt the non-maskable interrupt request to the nvic is controlled by the external nmi signal. the pin the nmi signal is multiplexed on, must be configured for the nmi function to generate the non-maskable interrupt request. 3.3.2.3 interrupt channel assignments the interrupt vector assignments are defined in the following table. ? vector number the value stored on the stack when an interrupt is serviced. ? irq number non-core interrupt source count, which is the vector number minus 16. the irq number is used within arm's nvic documentation. table 3-7. interrupt vector assignments address vector irq 1 nvic ipr register number 2 source module source description arm core system handler vectors 0x0000_0000 0 arm core initial stack pointer 0x0000_0004 1 arm core initial program counter table continues on the next page... chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 47
table 3-7. interrupt vector assignments (continued) address vector irq 1 nvic ipr register number 2 source module source description 0x0000_0008 2 arm core non-maskable interrupt (nmi) 0x0000_000c 3 arm core hard fault 0x0000_0010 4 0x0000_0014 5 0x0000_0018 6 0x0000_001c 7 0x0000_0020 8 0x0000_0024 9 0x0000_0028 10 0x0000_002c 11 arm core supervisor call (svcall) 0x0000_0030 12 0x0000_0034 13 0x0000_0038 14 arm core pendable request for system service (pendablesrvreq) 0x0000_003c 15 arm core system tick timer (systick) non-core vectors 0x0000_0040 16 0 0 dma dma channel 0 transfer complete and error 0x0000_0044 17 1 0 dma dma channel 1 transfer complete and error 0x0000_0048 18 2 0 dma dma channel 2 transfer complete and error 0x0000_004c 19 3 0 dma dma channel 3 transfer complete and error 0x0000_0050 20 4 1 0x0000_0054 21 5 1 ftfa command complete and read collision 0x0000_0058 22 6 1 pmc low-voltage detect, low-voltage warning 0x0000_005c 23 7 1 llwu low leakage wakeup 0x0000_0060 24 8 2 i 2 c0 0x0000_0064 25 9 2 0x0000_0068 26 10 2 spi0 single interrupt vector for all sources 0x0000_006c 27 11 2 0x0000_0070 28 12 3 uart0 status and error 0x0000_0074 29 13 3 0x0000_0078 30 14 3 0x0000_007c 31 15 3 adc0 0x0000_0080 32 16 4 cmp0 0x0000_0084 33 17 4 tpm0 0x0000_0088 34 18 4 tpm1 0x0000_008c 35 19 4 0x0000_0090 36 20 5 rtc alarm interrupt 0x0000_0094 37 21 5 rtc seconds interrupt table continues on the next page... core modules kl04 sub-family reference manual, rev. 3.1, november 2012 48 freescale semiconductor, inc.
table 3-7. interrupt vector assignments (continued) address vector irq 1 nvic ipr register number 2 source module source description 0x0000_0098 38 22 5 pit single interrupt vector for all channels 0x0000_009c 39 23 5 0x0000_00a0 40 24 6 0x0000_00a4 41 25 6 0x0000_00a8 42 26 6 0x0000_00ac 43 27 6 mcg 0x0000_00b0 44 28 7 lptmr0 0x0000_00b4 45 29 7 0x0000_00b8 46 30 7 port control module pin detect (port a) 0x0000_00bc 47 31 7 port control module pin detect (port b ) 1. indicates the nvic's interrupt source number. 2. indicates the nvic's ipr register number used for this irq. the equation to calculate this value is: irq div 4 3.3.2.3.1 determining the bitfield and register location for configuring a particular interrupt suppose you need to configure the spi0 interrupt. the following table is an excerpt of the spi0 row from interrupt priority levels . table 3-8. interrupt vector assignments address vector irq 1 nvic ipr register number 2 source module source description 0x0000_0068 26 10 2 spi0 single interrupt vector for all sources 1. indicates the nvic's interrupt source number. 2. indicates the nvic's ipr register number used for this irq. the equation to calculate this value is: irq div 4. ? the nvic registers you would use to configure the interrupt are: ? nvicipr2 ? to determine the particular irq's bitfield location within these particular registers: ? nvicipr2 bitfield starting location = 8 * (irq mod 4) + 6 = 22 since the nvicipr bitfields are 2-bit wide (4 priority levels), the nvicipr2 bitfield range is 22-23 therefore, the following bitfield locations are used to configure the spi0 interrupts: ? nvicipr2[23:22] chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 49
3.3.3 asynchronous wake-up interrupt controller (awic) configuration this section summarizes how the module has been configured in the chip. full documentation for this module is provided by arm and can be found at www.arm.com . asynchronous wake-up interrupt controller (awic) nested vectored interrupt controller (nvic) wake-up requests module module clock logic figure 3-3. asynchronous wake-up interrupt controller configuration table 3-9. reference links to related information topic related module reference system memory map system memory map clocking clock distribution power management power management nested vectored interrupt controller (nvic) nvic wake-up requests awic wake-up sources 3.3.3.1 wake-up sources the device uses the following internal and external inputs to the awic module. table 3-10. awic stop wake-up sources wake-up source description available system resets reset pin when lpo is its clock source low-voltage detect power management controller - functional in stop mode low-voltage warning power management controller - functional in stop mode pin interrupts port control module - any enabled pin interrupt is capable of waking the system adc the adc is functional when using internal clock source cmp0 interrupt in normal or trigger mode table continues on the next page... core modules kl04 sub-family reference manual, rev. 3.1, november 2012 50 freescale semiconductor, inc.
table 3-10. awic stop wake-up sources (continued) wake-up source description i 2 cx address match wakeup uart0 any interrupt provided clock remains enabled rtc alarm or seconds interrupt nmi nmi pin tpmx any interrupt provided clock remains enabled lptmr any interrupt provided clock remains enabled spi slave mode interrupt system modules 3.4.1 sim configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. register access peripheral bridge system integration module (sim) figure 3-4. sim configuration table 3-11. reference links to related information topic related module reference full description sim sim system memory map system memory map clocking clock distribution power management power management 3.4 chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 51
3.4.2 system mode controller (smc) configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. power management controller (pmc) register access peripheral bridge system mode controller (smc) resets figure 3-5. system mode controller configuration table 3-12. reference links to related information topic related module reference full description system mode controller (smc) smc system memory map system memory map power management power management power management controller (pmc) pmc low-leakage wakeup unit (llwu) llwu reset control module (rcm) reset 3.4.2.1 vlls2 not supported vlls2 power mode is not supported on this device. 3.4.3 pmc configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. system modules kl04 sub-family reference manual, rev. 3.1, november 2012 52 freescale semiconductor, inc.
register access power management controller (pmc) module signals peripheral bridge module signals system mode controller (smc) low-leakage wakeup unit figure 3-6. pmc configuration table 3-13. reference links to related information topic related module reference full description pmc pmc system memory map system memory map power management power management full description system mode controller (smc) system mode controller low-leakage wakeup unit (llwu) llwu reset control module (rcm) reset 3.4.4 low-leakage wake-up unit (llwu) configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 53
low-leakage wake-up unit (llwu) power management controller (pmc) peripheral bridge 0 register access wake-up requests module module figure 3-7. low-leakage wake-up unit configuration table 3-14. reference links to related information topic related module reference full description llwu llwu system memory map system memory map clocking clock distribution power management power management chapter power management controller (pmc) power management controller (pmc) system mode controller (smc) system mode controller wake-up requests llwu wake-up sources 3.4.4.1 llwu interrupt note do not mask the llwu interrupt when in lls mode. masking the interrupt prevents the device from exiting stop mode when a wakeup is detected. 3.4.4.2 wake-up sources the device uses the following internal peripheral and external pin inputs as wakeup sources to the llwu module. llwu_px are external pin inputs, and llwu_m0if- m7if are connections to the internal peripheral interrupt flags. note in addition to the llwu wakeup sources, the device also wakes from low power modes when nmi or reset pins are enabled and the respective pin is asserted. system modules kl04 sub-family reference manual, rev. 3.1, november 2012 54 freescale semiconductor, inc.
table 3-15. llwu wakeup sources irq module source or pin name llwu_p0 pta4 llwu_p1 pta5 llwu_p2 pta6 llwu_p3 pta7 llwu_p4 ptb0 llwu_p5 ptb2 llwu_p6 ptb4 llwu_p7 pta0 llwu_m0if lptmr0 llwu_m1if cmp0 llwu_m2if reserved llwu_m3if reserved llwu_m4if tsi0 llwu_m5if rtc alarm llwu_m6if reserved llwu_m7if rtc seconds 3.4.5 mcm configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. miscellaneous control module (mcm) transfers arm cortex-m0+ core flash memory controller transfers figure 3-8. mcm configuration table 3-16. reference links to related information topic related module reference full description miscellaneous control module (mcm) mcm system memory map system memory map clocking clock distribution power management power management private peripheral bus (ppb) arm cortex-m0+ core arm cortex-m0+ core table continues on the next page... chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 55
table 3-16. reference links to related information (continued) topic related module reference transfer flash memory controller flash memory controller 3.4.6 crossbar-light switch configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. crossbar switch slave modules master modules m2 m0 s0 s2 arm core unified bus dma flash controller s1 sraml bme peripheral bridge 0 gpio controller sramu peripherals figure 3-9. crossbar-light switch integration table 3-17. reference links to related information topic related module reference full description crossbar switch crossbar switch system memory map system memory map clocking clock distribution crossbar switch master arm cortex-m0+ core arm cortex-m0+ core crossbar switch master dma controller dma controller crossbar switch slave flash memory controller flash memory controller crossbar switch slave sram controller sram configuration crossbar switch slave peripheral bridge peripheral bridge 2-ported peripheral gpio controller gpio controleer system modules kl04 sub-family reference manual, rev. 3.1, november 2012 56 freescale semiconductor, inc.
3.4.6.1 crossbar-light switch master assignments the masters connected to the crossbar switch are assigned as follows: master module master port number arm core unified bus 0 dma 2 3.4.6.2 crossbar switch slave assignments this device contains 3 slaves connected to the crossbar switch. the slave assignment is as follows: slave module slave port number flash memory controller 0 sram controller 1 peripheral bridge 0 2 3.4.7 peripheral bridge configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. peripherals transfers aips-lite peripheral bridge transfers crossbar switch figure 3-10. peripheral bridge configuration table 3-18. reference links to related information topic related module reference full description peripheral bridge (aips-lite) peripheral bridge (aips-lite) system memory map system memory map clocking clock distribution crossbar switch crossbar switch crossbar switch chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 57
3.4.7.1 number of peripheral bridges this device contains one peripheral bridge. 3.4.7.2 memory maps the peripheral bridges are used to access the registers of most of the modules on this device. see aips0 memory map for the memory slot assignment for each module. 3.4.8 dma request multiplexer configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. dma request multiplexer dma controller requests module module module peripheral bridge 0 register access channel request figure 3-11. dma request multiplexer configuration table 3-19. reference links to related information topic related module reference full description dma request multiplexer dma mux system memory map system memory map clocking clock distribution power management power management channel request dma controller dma controller requests dma request sources system modules kl04 sub-family reference manual, rev. 3.1, november 2012 58 freescale semiconductor, inc.
3.4.8.1 dma mux request sources this device includes a dma request mux that allows up to 63 dma request signals to be mapped to any of the 4 dma channels. because of the mux there is no hard correlation between any of the dma request sources and a specific dma channel. some of the modules support asynchronous dma operation as indicated by the last column in the following dma source assignment table. table 3-20. dma request sources - mux 0 source number source module source description async dma capable 0 channel disabled 1 1 reserved not used 2 uart0 receive yes 3 uart0 transmit yes 4 reserved 5 reserved 6 reserved 7 reserved 8 reserved 9 reserved 10 reserved 11 reserved 12 reserved 13 reserved 14 reserved 15 reserved 16 spi0 receive 17 spi0 transmit 18 reserved 19 reserved 20 reserved 21 reserved 22 i 2 c0 23 reserved 24 tpm0 channel 0 yes 25 tpm0 channel 1 yes 26 tpm0 channel 2 yes 27 tpm0 channel 3 yes 28 tpm0 channel 4 yes 29 tpm0 channel 5 yes 30 reserved table continues on the next page... chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 59
table 3-20. dma request sources - mux 0 (continued) source number source module source description async dma capable 31 reserved 32 tpm1 channel 0 yes 33 tpm1 channel 1 yes 34 reserved 35 reserved 36 reserved 37 reserved 38 reserved 39 reserved 40 adc0 yes 41 reserved 42 cmp0 yes 43 reserved 44 reserved 45 reserved 46 reserved 47 reserved 48 reserved 49 port control module port a yes 50 port control module port b yes 51 reserved 52 reserved 53 reserved 54 tpm0 overflow yes 55 tpm1 overflow yes 56 reserved 57 reserved 58 reserved 59 reserved 60 dma mux always enabled 61 dma mux always enabled 62 dma mux always enabled 63 dma mux always enabled 1. configuring a dma channel to select source 0 or any of the reserved sources disables that dma channel. system modules kl04 sub-family reference manual, rev. 3.1, november 2012 60 freescale semiconductor, inc.
3.4.8.2 dma transfers via pit trigger the pit module can trigger a dma transfer on the first two dma channels. the assignments are detailed at pit/dma periodic trigger assignments . 3.4.9 dma controller configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. dma controller crossbar switch requests peripheral bridge 0 register access transfers dma multiplexer figure 3-12. dma controller configuration table 3-21. reference links to related information topic related module reference full description dma controller dma controller system memory map system memory map clocking clock distribution power management power management crossbar switch crossbar switch crossbar switch requests dma request sources 3.4.10 computer operating properly (cop) watchdog configuration this section summarizes how the module has been configured in the chip. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 61
wdog mode controller peripheral bridge 0 register access figure 3-13. cop watchdog configuration table 3-22. reference links to related information topic related module reference clocking clock distribution power management power management programming model system integration module (sim) sim 3.4.10.1 cop clocks the two clock inputs for the cop are the 1 khz clock and the bus clock. 3.4.10.2 cop watchdog operation the cop watchdog is intended to force a system reset when the application software fails to execute as expected. to prevent a system reset from the cop timer (when it is enabled), application software must reset the cop counter periodically. if the application program gets lost and fails to reset the cop counter before it times out, a system reset is generated to force the system back to a known starting point. after any reset, the cop watchdog is enabled. if the cop watchdog is not used in an application, it can be disabled by clearing copctrl[copt] in the sim. the cop counter is reset by writing 0x55 and 0xaa (in that order) to the address of the sim's service cop (srvcop) register during the selected timeout period. writes do not affect the data in the srvcop register. as soon as the write sequence is complete, the cop timeout period is restarted. if the program fails to perform this restart during the timeout period, the microcontroller resets. also, if any value other than 0x55 or 0xaa is written to the srvcop register, the microcontroller immediately resets. system modules kl04 sub-family reference manual, rev. 3.1, november 2012 62 freescale semiconductor, inc.
the sim's copctrl[copclks] field selects the clock source used for the cop timer. the clock source options are either the bus clock or an internal 1 khz clock source. with each clock source, there are three associated timeouts controlled by copctrl[copt]. the following table summarizes the control functions of the copclks and copt bits. the cop watchdog defaults to operation from the 1 khz clock source and the longest timeout for that clock source (2 10 cycles). table 3-23. cop configuration options control bits clock source cop window opens (copctrl[copw]=1) cop overflow count copctrl[copclks] copctrl[copt] n/a 00 n/a n/a cop is disabled 0 01 1 khz n/a 2 5 cycles (32 ms) 0 10 1 khz n/a 2 8 cycles (256 ms) 0 11 1 khz n/a 2 10 cycles (1024 ms) 1 01 bus 6,144 cycles 2 13 cycles 1 10 bus 49,152 cycles 2 16 cycles 1 11 bus 196,608 cycles 2 18 cycles after the bus clock source is selected, windowed cop operation is available by setting copctrl[copw] in the sim. in this mode, writes to the srvcop register to clear the cop timer must occur in the last 25% of the selected timeout period. a premature write immediately resets the chip. when the 1 khz clock source is selected, windowed cop operation is not available. the cop counter is initialized by the first writes to the sim's copctrl register and after any system reset. subsequent writes to the sim's copctrl register have no effect on cop operation. even if an application uses the reset default settings of the copt, copclks, and copw bits, the user should write to the write-once copctrl register during reset initialization to lock in the settings. this approach prevents accidental changes if the application program becomes lost. the write to the srvcop register that services (clears) the cop counter should not be placed in an interrupt service routine (isr) because the isr could continue to be executed periodically even if the main application program fails. if the bus clock source is selected, the cop counter does not increment while the microcontroller is in debug mode or while the system is in stop (including vlps or lls) mode. the cop counter resumes when the microcontroller exits debug mode or stop mode. if the 1 khz clock source is selected, the cop counter is re-initialized to zero upon entry to either debug mode or stop (including vlps or lls) mode. the counter begins from zero upon exit from debug mode or stop mode. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 63
regardless of the clock selected, the cop is disabled when the chip enters a vllsx mode. upon a reset that wakes the chip from the vllsx mode, the cop is re-initialized and enabled as for any reset. 3.4.10.3 clock gating this family of devices includes clock gating control for each peripheral, that is, the clock to each peripheral can explicitly be gated on or off, using clock-gate control bits in the sim module. clock modules 3.5.1 mcg configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. register access peripheral bridge multipurpose clock generator (mcg) system oscillator system integration module (sim) figure 3-14. mcg configuration table 3-24. reference links to related information topic related module reference full description mcg mcg system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing 3.5 clock modules kl04 sub-family reference manual, rev. 3.1, november 2012 64 freescale semiconductor, inc.
3.5.1.1 mcg fll modes on l-series devices the mcgfllclk frequency is limited to 48 mhz max. the dco is limited to the two lowest range settings (mcg_c4[drst_drs] must be set to either 0b00 or 0b01). 3.5.2 osc configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. signal multiplexing register access peripheral bridge system oscillator mcg module signals rtc figure 3-15. osc configuration table 3-25. reference links to related information topic related module reference full description osc osc system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing full description mcg mcg 3.5.2.1 osc modes of operation with mcg and rtc the most common method of controlling the osc block is through mcg clock source selection mcg_c1[clks] and the mcg_c2 register bits to configure the oscillator frequency range, gain-mode, and for crystal or external clock operation. the osc_cr also provides control for enabling the osc and configuring internal load capacitors for the extal and xtal pins. see the osc and mcg chapters for more details. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 65
the rtc_cr[osce] bit has overriding control over the mcg and osc_cr enable functions. when rtc_cr[osce] is set, the osc is configured for low frequency, low power and the rtc_cr[scxp] bits override the osc_cr[scxp] bits to control the internal capacitance configuration. see the rtc chapter for more details. memories and memory interfaces 3.6.1 flash memory configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. register access flash memory transfers flash memory controller peripheral bus controller 0 figure 3-16. flash memory configuration table 3-26. reference links to related information topic related module reference full description flash memory flash memory system memory map system memory map clocking clock distribution transfers flash memory controller flash memory controller register access peripheral bridge peripheral bridge 3.6.1.1 flash memory sizes the devices covered in this document contain 1 program flash block consisting of 1 kb sectors. the amounts of flash memory for the devices covered in this document are: 3.6 memories and memory interfaces kl04 sub-family reference manual, rev. 3.1, november 2012 66 freescale semiconductor, inc.
table 3-27. kl04 flash memory size device program flash (kb) block 0 (p-flash) address range mkl04z8vfk4 8 0x0000_0000 C 0x0000_1fff mkl04z16vfk4 16 0x0000_0000 C 0x0000_3fff mkl04z32vfk4 32 0x0000_0000 C 0x0000_7fff mkl04z8vlc4 8 0x0000_0000 C 0x0000_1fff mkl04z16vlc4 16 0x0000_0000 C 0x0000_3fff mkl04z32vlc4 32 0x0000_0000 C 0x0000_7fff mkl04z8vfm4 8 0x0000_0000 C 0x0000_1fff MKL04Z16VFM4 16 0x0000_0000 C 0x0000_3fff mkl04z32vfm4 32 0x0000_0000 C 0x0000_7fff mkl04z16vlf4 16 0x0000_0000 C 0x0000_3fff mkl04z32vlf4 32 0x0000_0000 C 0x0000_7fff 3.6.1.2 flash memory map the flash memory and the flash registers are located at different base addresses as shown in the following figure. the base address for each is specified in system memory map . program flash flash configuration field program flash base address flash memory base address registers figure 3-17. flash memory map the on-chip flash is implemented in a portion of the allocated flash range to form a contiguous block in the memory map beginning at address 0x0000_0000. see flash memory sizes for details of supported ranges. accesses to the flash memory ranges outside the amount of flash on the device causes the bus cycle to be terminated with an error followed by the appropriate response in the requesting bus master. read collision events in which flash memory is accessed while a flash memory resource is being manipulated by a flash command also generates a bus error response. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 67
3.6.1.3 flash security how flash security is implemented on this device is described in chip security . 3.6.1.4 flash modes the flash memory chapter defines two modes of operation - nvm normal and nvm special modes. on this device, the flash memory only operates in nvm normal mode. all references to nvm special mode should be ignored. 3.6.1.5 erase all flash contents in addition to software, the entire flash memory may be erased external to the flash memory via the sw-dp debug port by setting mdm-ap control[0]. mdm-ap status[0] is set to indicate the mass erase command has been accepted. mdm-ap status[0] is cleared when the mass erase completes. 3.6.1.6 ftfa_fopt register the flash memory's ftfa_fopt register allows the user to customize the operation of the mcu at boot time. see fopt boot options for details of its definition. 3.6.2 flash memory controller configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. see mcm_placr register description for details on the reset configuration of the fmc. memories and memory interfaces kl04 sub-family reference manual, rev. 3.1, november 2012 68 freescale semiconductor, inc.
flash memory controller transfers transfers flash memory crossbar switch mcm figure 3-18. flash memory controller configuration table 3-28. reference links to related information topic related module reference full description flash memory controller flash memory controller system memory map system memory map clocking clock distribution transfers flash memory flash memory transfers crossbar switch crossbar switch register access mcm mcm 3.6.3 sram configuration this section summarizes how the module has been configured in the chip. sram upper transfers cortex-m0+ core switch sram lower crossbar sram controller figure 3-19. sram configuration table 3-29. reference links to related information topic related module reference full description sram sram system memory map system memory map clocking clock distribution arm cortex-m0+ core arm cortex-m0+ core chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 69
3.6.3.1 sram sizes this device contains sram which could be accessed by bus masters through the cross- bar switch. the amount of sram for the devices covered in this document is shown in the following table. table 3-30. kl04 sram memory size device sram (kb) mkl04z8vfk4 1 mkl04z16vfk4 2 mkl04z32vfk4 4 mkl04z8vlc4 1 mkl04z16vlc4 2 mkl04z32vlc4 4 mkl04z8vfm4 1 MKL04Z16VFM4 2 mkl04z32vfm4 4 mkl04z16vlf4 2 mkl04z32vlf4 4 3.6.3.2 sram ranges the on-chip sram is split into two ranges, 1/4 is allocated sram_l and 3/4 is allocated to sram_u. the on-chip ram is implemented such that the sram_l and sram_u ranges form a contiguous block in the memory map. as such: ? sram_l is anchored to 0x1fff_ffff and occupies the space before this ending address. ? sram_u is anchored to 0x2000_0000 and occupies the space after this beginning address. valid address ranges for sram_l and sram_u are then defined as: ? sram_l = [0x2000_0000C(sram_size/4)] to 0x1fff_ffff ? sram_u = 0x2000_0000 to [0x2000_0000+(sram_size*(3/4))-1] this is illustrated in the following figure. memories and memory interfaces kl04 sub-family reference manual, rev. 3.1, november 2012 70 freescale semiconductor, inc.
sram_u 0x2000_0000 sram size *(1/4) sram_l 0x1fff_ffff sram size * (3/4) 0x2000_0000 C sram_size/4 0x2000_0000 + sram_size(3/4) - 1 figure 3-20. sram blocks memory map for example, for a device containing 16 kb of sram the ranges are: ? sram_l: 0x1fff_f000 C 0x1fff_ffff ? sram_u: 0x2000_0000 C 0x2000_2fff 3.6.3.3 sram retention in low power modes the sram is retained down to vlls3 mode. in vlls1 and vlls0 no sram is retained. analog 3.7.1 12-bit sar adc configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. 3.7 chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 71
signal multiplexing module signals register access 12-bit sar adc peripheral bus controller 0 other peripherals figure 3-21. 12-bit sar adc configuration table 3-31. reference links to related information topic related module reference full description 12-bit sar adc 12-bit sar adc system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing 3.7.1.1 adc instantiation information this device contains one 12-bit successive approximation adc with up to 14-channels. the adc supports both software and hardware triggers. the hardware trigger sources are listed in the module-to-module section . the number of adc channels present on the device is determined by the pinout of the specific device package and is shown in the following table. table 3-32. number of kl04 adc channels device number of adc channels mkl04z8vfk4 12 mkl04z16vfk4 12 mkl04z32vfk4 12 mkl04z8vlc4 14 mkl04z16vlc4 14 mkl04z32vlc4 14 mkl04z8vfm4 14 MKL04Z16VFM4 14 mkl04z32vfm4 14 mkl04z16vlf4 14 table continues on the next page... analog kl04 sub-family reference manual, rev. 3.1, november 2012 72 freescale semiconductor, inc.
table 3-32. number of kl04 adc channels (continued) device number of adc channels mkl04z32vlf4 14 3.7.1.2 dma support on adc applications may require continuous sampling of the adc that may have considerable load on the cpu. the adc supports dma request functionality for higher performance when the adc is sampled at a very high rate. the adc can trigger the dma (via dma req) on conversion completion. 3.7.1.3 adc0 connections/channel assignment 3.7.1.3.1 adc0 channel assignment adc channel (sc1n[adch]) channel input signal (sc1n[diff]= 1) input signal (sc1n[diff]= 0) 00000 ad0 reserved adc0_se0 00001 ad1 reserved adc0_se1 00010 ad2 reserved adc0_se2 00011 ad3 reserved adc0_se3 00100 ad4 reserved adc0_se4 00101 ad5 reserved adc0_se5 00110 ad6 reserved adc0_se6 00111 ad7 reserved adc0_se7 01000 ad8 reserved adc0_se8 01001 ad9 reserved adc0_se9 01010 ad10 reserved adc0_se10 01011 ad11 reserved adc0_se11 01100 ad12 reserved adc0_se12 01101 ad13 reserved adc0_se13 01110 ad14 reserved reserved 01111 ad15 reserved reserved 10000 ad16 reserved reserved 10001 ad17 reserved reserved 10010 ad18 reserved reserved 10011 ad19 reserved reserved 10100 ad20 reserved reserved table continues on the next page... chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 73
adc channel (sc1n[adch]) channel input signal (sc1n[diff]= 1) input signal (sc1n[diff]= 0) 10101 ad21 reserved reserved 10110 ad22 reserved reserved 10111 ad23 reserved reserved 11000 ad24 reserved reserved 11001 ad25 reserved reserved 11010 ad26 temperature sensor (diff) temperature sensor (s.e) 11011 ad27 bandgap (diff) 1 bandgap (s.e) 1 11100 ad28 reserved reserved 11101 ad29 -vrefh (diff) vrefh (s.e) 11110 ad30 reserved vrefl 11111 ad31 module disabled module disabled 1. this is the pmc bandgap 1v reference voltage. prior to reading from this adc channel, ensure that you enable the bandgap buffer by setting the pmc_regsc[bgbe] bit. refer to the device data sheet for the bandgap voltage (v bg ) specification. 3.7.1.4 adc analog supply and reference connections this device internally connects vdda to vdd and vssa to vss. this device contains separate vrefh and vrefl pins on 32-pin and higher devices. these pins are internally connected to vdd and vss respectively, on packages less than 32-pin. 3.7.1.5 adc reference options the adc supports the following references: ? vrefh/vrefl - connected as the primary reference option ? vdda - connected as the v alt reference option 3.7.1.6 alternate clock for this device, the alternate clock is connected to oscerclk. note this clock option is only usable when oscerclk is in the mhz range. a system with oscerclk in the khz range has the optional clock source below minimum adc clock operating frequency. analog kl04 sub-family reference manual, rev. 3.1, november 2012 74 freescale semiconductor, inc.
3.7.2 cmp configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. signal multiplexing module signals register access cmp peripheral bridge 0 other peripherals figure 3-22. cmp configuration table 3-33. reference links to related information topic related module reference full description comparator (cmp) comparator system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing 3.7.2.1 cmp instantiation information the device includes one high speed comparator and two 8-input multiplexors for both the inverting and non-inverting inputs of the comparator. each cmp input channel connects to both muxes. two of the channels are connected to internal sources, leaving resources to support up to 6 input pins. see the channel assignment table for a summary of cmp input connections for this device. the cmp also includes one 6-bit dac with a 64-tap resistor ladder network, which provides a selectable voltage reference for applications where voltage reference is needed for internal connection to the cmp. the cmp can be optionally on in all modes except vlls0. the cmp has several module to module interconnects in order to facilitate adc triggering, tpm triggering and uart ir interfaces. for complete details on the cmp module interconnects please refer to the module-to-module section. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 75
the cmp does not support window compare function and cmp_cr1[we] must always be written to 0. the sample function has limited functionality since the sample input to the block is not connected to a valid input. usage of sample operation is limited to a divided version of the bus clock (cmp_cr1[se] = 0). due to the pin number limitation, the cmp pass through mode is not supported by this device, so the cmpx_muxcr[pstm] must be left as 0. 3.7.2.2 cmp input connections the following table shows the fixed internal connections to the cmp. table 3-34. cmp input connections cmp inputs cmp0 in0 cmp0_in0 in1 cmp0_in1 in2 cmp0_in2 in3 cmp0_in3 in4 in5 in6 bandgap 1 in7 6-bit dac0 reference 1. this is the pmc bandgap 1v reference voltage. prior to using as cmp input, ensure that you enable the bandgap buffer by setting the pmc_regsc[bgbe] bit. refer to the device data sheet for the bandgap voltage (v bg ) specification. 3.7.2.3 cmp external references the 6-bit dac sub-block supports selection of two references. for this device, the references are connected as follows: ? vrefh - v in1 input. when using vrefh, any adc conversion using this same reference at the same time is negatively impacted. ? vdd - v in2 input 3.7.2.4 cmp trigger mode the cmp and 6-bit dac sub-block supports trigger mode operation when the cmp_cr1[trigm] is set. when trigger mode is enabled, the trigger event will initiate a compare sequence that must first enable the cmp and dac prior to performing a cmp operation and capturing the output. in this device, control for this two staged sequencing analog kl04 sub-family reference manual, rev. 3.1, november 2012 76 freescale semiconductor, inc.
is provided from the lptmr. the lptmr triggering output is always enabled when the lptmr is enabled. the first signal is supplied to enable the cmp and dac and is asserted at the same time as the tcf flag is set. the delay to the second signal that triggers the cmp to capture the result of the compare operation is dependent on the lptmr configuration. in time counter mode with prescaler enabled, the delay is 1/2 prescaler output period. in time counter mode with prescaler bypassed, the delay is 1/2 prescaler clock period. the delay between the first signal from lptmr and the second signal from lptmr must be greater than the analog comparator initialization delay as defined in the device datasheet. timers 3.8.1 timer/pwm module configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. signal multiplexing module signals register access tpm peripheral bus controller 0 other peripherals figure 3-23. tpm configuration table 3-35. reference links to related information topic related module reference full description timer/pwm module timer/pwm module system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing 3.8 chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 77
3.8.1.1 tpm instantiation information this device contains two low power tpm modules (tpm). all tpm modules in the device only are configured as basic tpm function, and no quadrature decoder function and all can be functional in stop/vlps mode. the clock source is either external or internal in stop/vlps mode. the following table shows how these modules are configured. table 3-36. tpm configuration tpm instance number of channels features/usage tpm0 6 basic tpm,functional in stop/vlps mode tpm1 2 basic tpm,functional in stop/vlps mode there are several connections to and from the tpms in order to facilitate customer use cases. for complete details on the tpm module interconnects please refer to the module- to-module section. 3.8.1.2 clock options the tpm blocks are clocked from a single tpm clock that can be selected from oscerclk, mcgirclk, or mcgfllclk. the selected source is controlled by sim_sopt2[tpmsrc] control registers. each tpm also supports an external clock mode (tpm_sc[cmod]=1x) in which the counter increments after a synchronized (to the selected tpm clock source) rising edge detect of an external clock input. the available external clock (either tpm_clkin0 or tpm_clkin1) is selected by sim_sopt4[tpmxclksel] control register. to guarantee valid operation the selected external clock must be less than half the frequency of the selected tpm clock source. 3.8.1.3 trigger options each tpm has a selectable trigger input source controlled by the tpmx_conf[trgsel] field to use for starting the counter and/or reloading the counter. the options available are shown in the following table. table 3-37. tpm trigger options tpmx_conf[trgsel] selected source 0000 external trigger pin input (extrg_in) table continues on the next page... timers kl04 sub-family reference manual, rev. 3.1, november 2012 78 freescale semiconductor, inc.
table 3-37. tpm trigger options (continued) tpmx_conf[trgsel] selected source 0001 cmp0 output 0010 reserved 0011 reserved 0100 pit trigger 0 0101 pit trigger 1 0110 reserved 0111 reserved 1000 tpm0 overflow 1001 tpm1 overflow 1010 reserved 1011 reserved 1100 rtc alarm 1101 rtc seconds 1110 lptmr trigger 1111 reserved 3.8.1.4 global timebase each tpm has a global timebase feature controlled by the tpmx_conf[gtbeen] bit. tpm1 is configured as the global time when this option is enabled. 3.8.1.5 tpm interrupts the tpm has multiple sources of interrupt. however, these sources are or'd together to generate a single interrupt request to the interrupt controller. when an tpm interrupt occurs, read the tpm status registers to determine the exact interrupt source. 3.8.2 pit configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 79
register access peripheral bridge periodic interrupt timer figure 3-24. pit configuration table 3-38. reference links to related information topic related module reference full description pit pit system memory map system memory map clocking clock distribution power management power management 3.8.2.1 pit/dma periodic trigger assignments the pit generates periodic trigger events to the dma channel mux as shown in the table below. table 3-39. pit channel assignments for periodic dma triggering pit channel dma channel number pit channel 0 dma channel 0 pit channel 1 dma channel 1 3.8.2.2 pit/adc triggers pit triggers are selected as adcx trigger sources using the sopt7[adcxtrgsel] bits in the sim module. for more details, refer to sim chapter. 3.8.2.3 pit/tpm triggers pit triggers are selected as tpmx trigger sources using the tpmx_conf[trgsel] bits in the tpm module. for more details, refer to tpm chapter. timers kl04 sub-family reference manual, rev. 3.1, november 2012 80 freescale semiconductor, inc.
3.8.2.4 pit/dac triggers pit channel 0 is configured as the dac hardware trigger source. for more details, refer to dac chapter. 3.8.3 low-power timer configuration signal multiplexing register access peripheral bridge module signals low-power timer figure 3-25. lpt configuration table 3-40. reference links to related information topic related module reference full description low-power timer low-power timer system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing 3.8.3.1 lptmr instantiation information the low-power timer (lptmr) allows operation during all power modes. the lptmr can operate as a real-time interrupt or pulse accumulator. it includes a 15-bit prescaler (real-time interrupt mode) or glitch filter (pulse accumulator mode). the lptmr can be clocked from the internal reference clock, the internal 1 khz lpo, oscerclk, or an external 32.768 khz crystal. in vlls0 mode, the clocking option is limited to an external pin with the osc configured for bypass (external clock) operation. an interrupt is generated (and the counter may reset) when the counter equals the value in the 16-bit compare register. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 81
3.8.3.2 lptmr pulse counter input options the lptmr_csr[tps] bitfield configures the input source used in pulse counter mode. the following table shows the chip-specific input assignments for this bitfield. lptmr_csr[tps] pulse counter input number chip input 00 0 cmp0 output 01 1 lptmr_alt1 pin 10 2 lptmr_alt2 pin 11 3 lptmr_alt3 pin 3.8.3.3 lptmr prescaler/glitch filter clocking options the prescaler and glitch filter of the lptmr module can be clocked from one of four sources determined by the lptmr0_psr[pcs] bitfield. the following table shows the chip-specific clock assignments for this bitfield. note the chosen clock must remain enabled if the lptmr is to continue operating in all required low-power modes. lptmr0_psr[pcs] prescaler/glitch filter clock number chip clock 00 0 mcgirclk internal reference clock (not available in lls and vlls modes) 01 1 lpo 1 khz clock (not available in vlls0 mode) 10 2 erclk32k (not available in vlls0 mode when using 32 khz oscillator) 11 3 oscerclk external reference clock (not available in vlls0 mode) see clock distribution for more details on these clocks. 3.8.4 rtc configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. timers kl04 sub-family reference manual, rev. 3.1, november 2012 82 freescale semiconductor, inc.
signal multiplexing register access peripheral bridge module signals real-time clock figure 3-26. rtc configuration table 3-41. reference links to related information topic related module reference full description rtc rtc system memory map system memory map clocking clock distribution power management power management 3.8.4.1 rtc instantiation information rtc prescaler is clocked by erclk32k. rtc is reset on por only. rtc_cr[osce] can override the configuration of the system osc, configuring the osc for 32 khz crystal operation in all power modes except vlls0, and through any system reset. when osce is enabled, the rtc also overrides the capacitor configurations. 3.8.4.2 rtc_clkout options rtc_clkout pin can be driven either with the rtc 1 hz output or with the oscerclk on-chip clock source. control for this option is through sim_sopt2[rtcclkoutsel] bit. when rtcclkoutsel = 0, the rtc 1 hz clock is output is selected on the rtc_clkout pin. when rtcclkoutsel = 1, oscerclk clock is output on the rtc_clkout pin. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 83
communication interfaces 3.9.1 spi configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. signal multiplexing register access spi peripheral bridge module signals figure 3-27. spi configuration table 3-42. reference links to related information topic related module reference full description spi spi system memory map system memory map clocking clock distribution signal multiplexing port control signal multiplexing 3.9.1.1 spi instantiation information this device contains one spi module that supports 8-bit data length. spi0 is clocked on the bus clock. the spi supports dma request and can operate in vlps mode. when the spi is operating in vlps mode, it will operate as a slave. spi can wakeup mcu from vlps mode upon reception of spi data in slave mode. 3.9 communication interfaces kl04 sub-family reference manual, rev. 3.1, november 2012 84 freescale semiconductor, inc.
3.9.2 i2c configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. signal multiplexing register access peripheral bridge module signals 2 i c figure 3-28. i2c configuration table 3-43. reference links to related information topic related module reference full description i 2 c i 2 c system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing 3.9.2.1 iic instantiation information this device has one iic module. when the package pins associated with iic have their mux select configured for iic operation, the pins (scl and sda) are driven in a pseudo open drain configuration. the digital glitch filter implemented in the iic0 module, controlled by the i2c0_flt[flt] registers, is clocked from the bus clock and thus has filter granularity in bus clock cycle counts. 3.9.3 uart configuration this section summarizes how the module has been configured in the chip. for a comprehensive description of the module itself, see the modules dedicated chapter. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 85
signal multiplexing register access peripheral bridge module signals uart figure 3-29. uart configuration table 3-44. reference links to related information topic related module reference full description uart0 uart system memory map system memory map clocking clock distribution power management power management signal multiplexing port control signal multiplexing 3.9.3.1 uart0 overview the uart0 module supports basic uart with dma interface function, x4 to x32 oversampling of baud-rate. this module supports lin slave operation. the module can remain functional in vlps mode provided the clock it is using remains enabled. iso7816 protocol is intended to be handled in software for this product. to support smart card reading, txd pin can be configured as pseudo open drain for 1-wire half-duplex like iso7816 communication via the sim_sopt5[uart0ode] bit. 3.9.3.2 uart1 and uart2 overview this device contains two basic universal asynchronous receiver/transmitter (uart) modules with dma function support. generally, these modules are used in rs-232, rs-485, and other communications. this module supports lin slave operation. communication interfaces kl04 sub-family reference manual, rev. 3.1, november 2012 86 freescale semiconductor, inc.
human-machine interfaces (hmi) 3.10.1 gpio configuration signal multiplexing register access peripheral bridge module signals gpio controller arm cortex -m0+ core register access figure 3-30. gpio configuration table 3-45. reference links to related information topic related module reference full description gpio gpio system memory map system memory map clocking clock distribution power management power management crossbar switch crossbar switch crossbar switch signal multiplexing port control signal multiplexing 3.10.1.1 gpio instantiation information the device includes four pins, ptb0, ptb1, pta12, and pta13, with high current drive capability. these pins can be used to drive led or power mosfet directly. the high drive capability applies to all functions which are multiplexed on these pins (uart, tpm, spi...etc) 3.10.1.1.1 pull devices and directions the pull devices are enabled out of por only on reset_b, nmi_b and respective swd signals. other pins can be enabled by writing to portx_pcrn[pe] field. 3.10 chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 87
all the pins are hard wired to be pullup except for swd_clk. the state will be reflected in the portx_pcrn[ps] field. 3.10.1.2 port control and interrupt summary the following table provides more information regarding the port control and interrupt configurations . table 3-46. ports summary feature port a port b pull select control no no pull select at reset pta0=pull down, others=pull up pull up pull enable control yes yes pull enable at reset pta0/pta2/reset_b=enabled; others=disabled ptb5=enabled; others=disabled slew rate enable control no no slew rate enable at reset pta2/pta6/pta7/pta15=disabled; others=enabled ptb0/ptb15/ptb16/ptb17= disabled; others=enabled passive filter enable control reset_b only ptb5 only passive filter enable at reset reset_b=enabled; others=disabled disabled open drain enable control 1 no no open drain enable at reset disabled disabled drive strength enable control pta12/pta13 only ptb0/ptb1 only drive strength enable at reset disabled disabled pin mux control yes yes pin mux at reset pta0/pta2=alt3; others=alt0 ptb5=alt3; others=alt0 lock bit no no interrupt and dma request pta0/pta1/pta7/pta10/pta11/ pta12/pta16/pta17/pta18 only ptb0/ptb1/ptb2/ptb3/ptb4/ptb5/ ptb6/ptb7/ptb14 only digital glitch filter no no 1. uart signals can be configured for open-drain using sim_sopt5 register. iic signals are automatically enabled for open drain when selected. 3.10.1.3 gpio accessibility in the memory map the gpio is multi-ported and can be accessed directly by the core with zero wait states at base address 0xf800_0000. it can also be accessed by the core and dma masters through the cross bar/aips interface at 0x400f_f000 and at an aliased slot (15) at human-machine interfaces (hmi) kl04 sub-family reference manual, rev. 3.1, november 2012 88 freescale semiconductor, inc.
address 0x4000_f000. all bme operations to the gpio space can be accomplished referencing the aliased slot (15) at address 0x4000_f000. only some of the bme operations can be accomplished referencing gpio at address 0x400f_f000. chapter 3 chip configuration kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 89
human-machine interfaces (hmi) kl04 sub-family reference manual, rev. 3.1, november 2012 90 freescale semiconductor, inc.
chapter 4 memory map 4.1 introduction this device contains various memories and memory-mapped peripherals which are located in a 4 gb memory space. this chapter describes the memory and peripheral locations within that memory space. 4.2 system memory map the following table shows the high-level device memory map. table 4-1. system memory map system 32-bit address range destination slave access 0x0000_0000C0x07ff_ffff 1 program flash and read-only data (includes exception vectors in first 196 bytes) all masters 0x0800_0000C0x1fff_fbff reserved 0x1fff_fc00-0x1fff_ffff 2 sram_l: lower sram all masters 0x2000_0000-0x2000_0bff 2 sram_u: upper sram all masters 0x2000_0c00C0x3fff_ffff reserved C 0x4000_0000C0x4007_ffff aips peripherals cortex-m0+ core & dma 0x4008_0000C0x400f_efff reserved C 0x400f_f000C0x400f_ffff general purpose input/output (gpio) cortex-m0+ core & dma 0x4010_0000C0x43ff_ffff reserved C 0x4400_0000C0x5fff_ffff bit manipulation engine (bme) access to aips peripherals for slots 0-127 3 cortex-m0+ core 0x6000_0000C0xdfff_ffff reserved C 0xe000_0000C0xe00f_ffff private peripherals cortex-m0+ core 0xe010_0000C0xefff_ffff reserved C 0xf000_0000C0xf000_0fff micro trace buffer (mtb) registers cortex-m0+ core table continues on the next page... kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 91
table 4-1. system memory map (continued) system 32-bit address range destination slave access 0xf000_1000C0xf000_1fff mtb data watchpoint and trace (mtbdwt) registers cortex-m0+ core 0xf000_2000C0xf000_2fff rom table cortex-m0+ core 0xf000_3000C0xf000_3fff miscellaneous control module (mcm) cortex-m0+ core 0xf000_4000C0xf7ff_ffff reserved C 0xf800_0000C0xffff_ffff ioport: gpio (single cycle) cortex-m0+ core 1. the program flash always begins at 0x0000_0000 but the end of implemented flash varies depending on the amount of flash implemented for a particular device. see flash memory sizes for details. 2. this range varies depending on sram sizes. see sram ranges for details. 3. includes bme operations to gpio at slot 15 (based at 0x4000_f000). 4.3 flash memory map the flash memory and the flash registers are located at different base addresses as shown in the following figure. the base address for each is specified in system memory map . program flash flash configuration field program flash base address flash memory base address registers figure 4-1. flash memory map the on-chip flash is implemented in a portion of the allocated flash range to form a contiguous block in the memory map beginning at address 0x0000_0000. see flash memory sizes for details of supported ranges. accesses to the flash memory ranges outside the amount of flash on the device causes the bus cycle to be terminated with an error followed by the appropriate response in the requesting bus master. read collision events in which flash memory is accessed while a flash memory resource is being manipulated by a flash command also generates a bus error response. flash memory map kl04 sub-family reference manual, rev. 3.1, november 2012 92 freescale semiconductor, inc.
4.3.1 alternate non-volatile irc user trim description the following non-volatile locations (4 bytes) are reserved for custom irc user trim supported by some development tools. an alternate irc trim to the factory loaded trim can be stored at this location. to override the factory trim, user software must load new values into the mcg trim registers. non-volatile byte address alternate irc trim value 0x0000_03fc reserved 0x0000_03fd reserved 0x0000_03fe (bit 0) scftrim 0x0000_03fe (bit 4:1) fctrim 0x0000_03ff sctrim 4.4 sram memory map the on-chip ram is split between sram_l and sram_u. the ram is also implemented such that the sram_l and sram_u ranges form a contiguous block in the memory map. see sram ranges for details. accesses to the sram_l and sram_u memory ranges outside the amount of ram on the device causes the bus cycle to be terminated with an error followed by the appropriate response in the requesting bus master. 4.5 bit manipulation engine the bit manipulation engine (bme) provides hardware support for atomic read-modify- write memory operations to the peripheral address space. by combining the basic load and store instruction support in the cortex-m instruction set architecture with the concept of decorated storage provided by the bme, the resulting implementation provides a robust and efficient read-modify-write capability to this class of ultra low-end microcontrollers. see the bit manipulation engine block guide (bme) for a detailed description of bme functionality. chapter 4 memory map kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 93
4.6 peripheral bridge (aips-lite) memory map the peripheral memory map is accessible via one slave port on the crossbar in the 0x4000_0000C0x400f_ffff region. the device implements one peripheral bridge that defines a 1024 kb address space. the three regions associated with this space are: ? a 128 kb region, partitioned as 32 spaces, each 4 kb in size and reserved for on- platform peripheral devices. the aips controller generates unique module enables for all 32 spaces. ? a 384 kb region, partitioned as 96 spaces, each 4 kb in size and reserved for off- platform modules. the aips controller generates unique module enables for all 96 spaces. ? the last slot is a 4 kb region beginning at 0x400f_f000 for accessing the gpio module. the gpio slot (slot 128) is an alias of slot 15. this block is also directly interfaced to the core and provides direct access without incurring wait states associated with accesses via the aips controller. modules that are disabled via their clock gate control bits in the sim registers disable the associated aips slots. access to any address within an unimplemented or disabled peripheral bridge slot results in a transfer error termination. for programming model accesses via the peripheral bridges, there is generally only a small range within the 4 kb slots that is implemented. accessing an address that is not implemented in the peripheral results in a transfer error termination. 4.6.1 read-after-write sequence and required serialization of memory operations in some situations, a write to a peripheral must be completed fully before a subsequent action can occur. examples of such situations include: ? exiting an interrupt service routine (isr) ? changing a mode ? configuring a function in these situations, application software must perform a read-after-write sequence to guarantee the required serialization of the memory operations: 1. write the peripheral register. 2. read the written peripheral register to verify the write. 3. continue with subsequent operations. peripheral bridge (aips-lite) memory map kl04 sub-family reference manual, rev. 3.1, november 2012 94 freescale semiconductor, inc.
4.6.2 peripheral bridge (aips-lite) memory map table 4-2. peripheral bridge 0 slot assignments system 32-bit base address slot number module 0x4000_0000 0 0x4000_1000 1 0x4000_2000 2 0x4000_3000 3 0x4000_4000 4 0x4000_5000 5 0x4000_6000 6 0x4000_7000 7 0x4000_8000 8 dma controller 0x4000_9000 9 0x4000_a000 10 0x4000_b000 11 0x4000_c000 12 0x4000_d000 13 0x4000_e000 14 0x4000_f000 15 gpio controller (aliased to 0x400f_f000) 0x4001_0000 16 0x4001_1000 17 0x4001_2000 18 0x4001_3000 19 0x4001_4000 20 0x4001_5000 21 0x4001_6000 22 0x4001_7000 23 0x4001_8000 24 0x4001_9000 25 0x4001_a000 26 0x4001_b000 27 0x4001_c000 28 0x4001_d000 29 0x4001_e000 30 0x4001_f000 31 0x4002_0000 32 flash memory 0x4002_1000 33 dma channel mutiplexer 0 0x4002_2000 34 table continues on the next page... chapter 4 memory map kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 95
table 4-2. peripheral bridge 0 slot assignments (continued) system 32-bit base address slot number module 0x4002_3000 35 0x4002_4000 36 0x4002_5000 37 0x4002_6000 38 0x4002_7000 39 0x4002_8000 40 0x4002_9000 41 0x4002_a000 42 0x4002_b000 43 0x4002_c000 44 0x4002_d000 45 0x4002_e000 46 0x4002_f000 47 0x4003_0000 48 0x4003_1000 49 0x4003_2000 50 0x4003_3000 51 0x4003_4000 52 0x4003_5000 53 0x4003_6000 54 0x4003_7000 55 periodic interrupt timers (pit) 0x4003_8000 56 timer'/pwm (tpm) 0 0x4003_9000 57 timer'/pwm (tpm) 1 0x4003_a000 58 0x4003_b000 59 analog-to-digital converter (adc) 0 0x4003_c000 60 0x4003_d000 61 real-time clock (rtc) 0x4003_e000 62 0x4003_f000 63 0x4004_0000 64 low-power timer (lptmr) 0x4004_1000 65 0x4004_2000 66 0x4004_3000 67 0x4004_4000 68 0x4004_5000 69 0x4004_6000 70 0x4004_7000 71 sim low-power logic 0x4004_8000 72 system integration module (sim) 0x4004_9000 73 port a multiplexing control table continues on the next page... peripheral bridge (aips-lite) memory map kl04 sub-family reference manual, rev. 3.1, november 2012 96 freescale semiconductor, inc.
table 4-2. peripheral bridge 0 slot assignments (continued) system 32-bit base address slot number module 0x4004_a000 74 port b multiplexing control 0x4004_b000 75 0x4004_c000 76 0x4004_d000 77 0x4004_e000 78 0x4004_f000 79 0x4005_0000 80 0x4005_1000 81 0x4005_2000 82 0x4005_3000 83 0x4005_4000 84 0x4005_5000 85 0x4005_6000 86 0x4005_7000 87 0x4005_8000 88 0x4005_9000 89 0x4005_a000 90 0x4005_b000 91 0x4005_c000 92 0x4005_d000 93 0x4005_e000 94 0x4005_f000 95 0x4006_0000 96 0x4006_1000 97 0x4006_2000 98 0x4006_3000 99 0x4006_4000 100 multi-purpose clock generator (mcg) 0x4006_5000 101 system oscillator (osc) 0x4006_6000 102 i 2 c 0 0x4006_7000 103 0x4006_8000 104 0x4006_9000 105 0x4006_a000 106 uart 0 0x4006_b000 107 0x4006_c000 108 0x4006_d000 109 0x4006_e000 110 0x4006_f000 111 0x4007_0000 112 table continues on the next page... chapter 4 memory map kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 97
table 4-2. peripheral bridge 0 slot assignments (continued) system 32-bit base address slot number module 0x4007_1000 113 0x4007_2000 114 0x4007_3000 115 analog comparator (cmp) / 6-bit digital-to-analog converter (dac) 0x4007_4000 116 0x4007_5000 117 0x4007_6000 118 spi 0 0x4007_7000 119 0x4007_8000 120 0x4007_9000 121 0x4007_a000 122 0x4007_b000 123 0x4007_c000 124 low-leakage wakeup unit (llwu) 0x4007_d000 125 power management controller (pmc) 0x4007_e000 126 system mode controller (smc) 0x4007_f000 127 reset control module (rcm) 0x400f_f000 128 gpio controller 4.6.3 modules restricted access in user mode in user mode, for mcg, rcm, sim (slot 71 and 72), smc, llwu, and pmc, reads are allowed, but writes are blocked and generate bus error. 4.7 private peripheral bus (ppb) memory map the ppb is part of the defined arm bus architecture and provides access to select processor-local modules. these resources are only accessible from the core; other system masters do not have access to them. table 4-3. ppb memory map system 32-bit address range resource additional range detail resource 0xe000_0000C0xe000_dfff reserved table continues on the next page... private peripheral bus (ppb) memory map kl04 sub-family reference manual, rev. 3.1, november 2012 98 freescale semiconductor, inc.
table 4-3. ppb memory map (continued) system 32-bit address range resource additional range detail resource 0xe000_e000C0xe000_efff system control space (scs) 0xe000_e000C0xe000_e00f reserved 0xe000_e010C0xe000_e0ff systick 0xe000_e100C0xe000_ecff nvic 0xe000_ed00C0xe000_ed8f system control block 0xe000_ed90C0xe000_edef reserved 0xe000_edf0C0xe000_eeff debug 0xe000_ef00C0xe000_efff reserved 0xe000_f000C0xe00f_efff reserved 0xe00f_f000C0xe00f_ffff core rom space (crs) chapter 4 memory map kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 99
private peripheral bus (ppb) memory map kl04 sub-family reference manual, rev. 3.1, november 2012 100 freescale semiconductor, inc.
chapter 5 clock distribution 5.1 introduction this chapter presents the clock architecture for the device, the overview of the clocks and includes a terminology section. the cortex m0+ resides within a synchronous core platform, where the processor and bus masters, flash and peripherals clocks can be configured independently. the clock distribution figure shows how clocks from the mcg and xosc modules are distributed to the microcontrollers other function units. some modules in the microcontroller have selectable clock input. 5.2 programming model the selection and multiplexing of system clock sources is controlled and programmed via the mcg module. the setting of clock dividers and module clock gating for the system are programmed via the sim module. reference those sections for detailed register and bit descriptions. 5.3 high-level device clocking diagram the following system oscillator , mcg , and sim module registers control the multiplexers, dividers, and clock gates shown in the below figure: osc mcg sim multiplexers mcg_c x mcg_c x sim_sopt1, sim_sopt2 dividers mcg_c x sim_clkdiv x clock gates osc_cr mcg_c1 sim_scgc x kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 101
32 khz irc fll mcgoutclk mcg outdiv1 4 mhz irc outdiv4 flash clock bus clock/ extal0 xtal0 system oscillator sim frdiv mcgirclk erclk32k xtal_clk oscerclk osc logic clock options for some peripherals (see note) clock options for some peripherals (see note) mcgfllclk note: see subsequent sections for details on where these clocks are used. pmc logic pmc lpo oscclk cg cg cg cg clock gate rtc_clkout rtc counter logic 1hz rtc_clkin osc32kclk cg fcrdiv core clock, platform clock, and system clock figure 5-1. clocking diagram 5.4 clock definitions the following table describes the clocks in the previous block diagram. clock name description core clock mcgoutclk divided by outdiv1, clocks the arm cortex- m0+ core platform clock mcgoutclk divided by outdiv1, clocks the crossbar switch and nvic system clock mcgoutclk divided by outdiv1, clocks the bus masters directly bus clock system clock divided by outdiv4, clocks the bus slaves and peripherals. table continues on the next page... clock definitions kl04 sub-family reference manual, rev. 3.1, november 2012 102 freescale semiconductor, inc.
clock name description flash clock flash memory clock. on this device it is the same as bus clock. mcgirclk mcg output of the slow or fast internal reference clock mcgoutclk mcg output of either irc, mcgfllclk or mcg's external reference clock that sources the core, system, bus, and flash clock. mcgfllclk mcg output of the fll. mcgfllclk may clock some modules. in addition, this clock is used for uart0 and tpm modules. oscclk system oscillator output of the internal oscillator or sourced directly from extal. used as mcg external reference clock. oscerclk system oscillator output sourced from oscclk that may clock some on-chip modules osc32kclk system oscillator 32khz output erclk32k clock source for some modules that is chosen as osc32kclk or rtc_clkin lpo pmc 1khz output 5.4.1 device clock summary the following table provides more information regarding the on-chip clocks. table 5-1. clock summary clock name run mode clock frequency vlpr mode clock frequency clock source clock is disabled when mcgoutclk up to 48 mhz up to 4 mhz mcg in all stop modes except for partial stop modes and during pll locking when mcgoutclk derived from pll. mcgfllclk up to 48 mhz n/a mcg mcg clock controls do not enable and in all stop modes core clock up to 48 mhz up to 4 mhz mcgoutclk clock divider in all wait and stop modes platform clock up to 48 mhz up to 4 mhz mcgoutclk clock divider in all stop modes system clock up to 48 mhz up to 4 mhz mcgoutclk clock divider in all stop modes and compute operation bus clock up to 24 mhz up to 1 mhz 1 mcgoutclk clock divider in all stop modes except for partial stop2 mode, and compute operation swd clock up to 24mhz up to 1mhz swd_clk pin in all stop modes table continues on the next page... chapter 5 clock distribution kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 103
table 5-1. clock summary (continued) clock name run mode clock frequency vlpr mode clock frequency clock source clock is disabled when flash clock up to 24 mhz up to 1 mhz in blpe up to 800 khz in blpi mcgoutclk clock divider in all stop modes except for partial stop2 mode internal reference (mcgirclk) 30-40 khz slow irc or 4 mhz fast irc 4 mhz fast irc only mcg mcg_c1[irclken] cleared, stop/vlps mode and mcg_c1[irefsten] cleared, or lls/vlls mode external reference (oscerclk) up to 48 mhz (bypass), 30-40 khz or 3-32 mhz (crystal) up to 16 mhz (bypass), 30-40 khz (low-range crystal) or 3-16 mhz (high-range crystal) system osc system osc's osc_cr[erclken] cleared, or stop mode and osc_cr[erefsten] cleared or vlls0 and oscillator not in external clock mode. external reference 32khz (erclk32k) 30-40 khz 30-40 khz system osc , or rtc_clkin system osc's osc_cr[erclken] cleared and rtc's rtc_cr[osce] cleared or vlls0 and oscillator not in external clock mode. rtc_clkout rtc 1hz, oscerclk rtc 1hz, oscerclk rtc 1hz, oscerclk clock is disabled in lls and vllsx modes lpo 1 khz 1 khz pmc in vlls0 tpm clock up to 48 mhz up to 8 mhz mcgirclk, mcgfllclk, or oscerclk sim_sopt2[tpmsrc ]=00 or selected clock source disabled. uart0 clock up to 48 mhz up to 8 mhz mcgirclk, mcgfllclk, or oscerclk sim_sopt2[uart0sr c]=00 or selected clock source disabled. 1. if in blpi mode, where clocking is derived from the fast internal reference clock, the bus clock and flash clock frequency needs to be limited to 800 khz if executing from flash. clock definitions kl04 sub-family reference manual, rev. 3.1, november 2012 104 freescale semiconductor, inc.
5.5 internal clocking requirements the clock dividers are programmed via the sim modules clkdiv registers. the following requirements must be met when configuring the clocks for this device: 1. the core, platform, and system clock are programmable from a divide-by-1 through divide-by-16 setting. the core, platform, and system clock frequencies must be 48 mhz or slower. 2. the bus clock and flash clock frequency is divided from the system clock and is programmable from a divide-by-1 through divide-by-8 setting. the bus clock and flash clock must be programmed to 24 mhz or slower. the following is a common clock configuration for this device: clock frequency core clock 48 mhz platform clock 48 mhz system clock 48 mhz bus clock 24 mhz flash clock 24 mhz 5.5.1 clock divider values after reset each clock divider is programmed via the sim modules clkdiv1 registers. two bits in the flash memory's ftfa_fopt register controls the reset value of the core clock, system clock, bus clock, and flash clock dividers as shown below: ftfa_fopt [4,0] core/system clock bus/flash clock description 00 0x7 (divide by 8) 0x1 (divide by 2) low power boot 01 0x3 (divide by 4) 0x1 (divide by 2) low power boot 10 0x1 (divide by 2) 0x1 (divide by 2) low power boot 11 0x0 (divide by 1) 0x1 (divide by 2) fast clock boot this gives the user flexibility in selecting between a lower frequency, low-power boot option vs. higher frequency, higher power during and after reset. chapter 5 clock distribution kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 105
the flash erased state defaults to fast clocking mode, since these bits reside in flash, which is logic 1 in the flash erased state. to enable a lower power boot option, program the appropriate bits in ftfa_fopt. during the reset sequence, if either of the control bits is cleared, the system is in a slower clock configuration. upon any system reset, the clock dividers return to this configurable reset state. 5.5.2 vlpr mode clocking the clock dividers cannot be changed while in vlpr mode. they must be programmed prior to entering vlpr mode to guarantee operation. max frequency limitations for vlpr mode is as follows : ? the core/system clocks are less than or equal to 4 mhz, and ? the bus and flash clocks are less than or equal to 1 mhz note when the mcg is in blpi and clocking is derived from the fast irc, the clock divider controls (mcg_sc[fcrdiv], sim_clkdiv1[outdiv1], and sim_clkdiv1[outdiv4]) must be programmed such that the resulting flash clock nominal frequency is 800 khz or less. in this case, one example of correct configuration is mcg_sc[fcrdiv]=000b, sim_clkdiv1[outdiv1]=0000b and sim_clkdiv1[outdiv4]=100b, resulting in a divide by 5 setting. 5.6 clock gating the clock to each module can be individually gated on and off using the sim module's scgc x registers. these bits are cleared after any reset, which disables the clock to the corresponding module to conserve power. prior to initializing a module, set the corresponding bit in scgc x register to enable the clock. before turning off the clock, make sure to disable the module. any bus access to a peripheral that has its clock disabled generates an error termination. 5.7 module clocks the following table summarizes the clocks associated with each module. clock gating kl04 sub-family reference manual, rev. 3.1, november 2012 106 freescale semiconductor, inc.
table 5-2. module clocks module bus interface clock internal clocks i/o interface clocks core modules arm cortex-m0+ core platform clock core clock nvic platform clock dap platform clock swd_clk system modules dma system clock dma mux bus clock port control bus clock crossbar switch platform clock peripheral bridges system clock bus clock llwu, pmc, sim, rcm bus clock lpo mode controller bus clock mcm platform clock watchdog timer bus clock lpo clocks mcg bus clock mcgoutclk, mcgfllclk, mcgirclk, oscerclk osc bus clock oscerclk memory and memory interfaces flash controller platform clock flash clock flash memory flash clock analog adc bus clock oscerclk cmp bus clock timers tpm bus clock tpm clock tpm_clkin0, tpm_clkin1 pit bus clock lptmr bus clock lpo, oscerclk, mcgirclk, erclk32k rtc bus clock erclk32k rtc_clkout communication interfaces spi0 bus clock spi0_sck i 2 c0 bus clock i2c0_scl uart0 bus clock uart0 clock human-machine interfaces gpio platform clock chapter 5 clock distribution kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 107
5.7.1 pmc 1-khz lpo clock the power management controller (pmc) generates a 1-khz clock that is enabled in all modes of operation, including all low power modes except vlls0. this 1-khz source is commonly referred to as lpo clock or 1-khz lpo clock. 5.7.2 cop clocking the cop may be clocked from two clock sources as shown in the following figure. sim_copctrl[copclks] cop clock bus clock lpo figure 5-2. cop clock generation 5.7.3 rtc clocking the rtc module can be clocked as shown in the following figure. note the chosen clock must remain enabled if the rtc is to continue operating in all required low-power modes. sim_sopt1[osc32ksel] osc32kclk rtc_clkin lpo erclk32k (to rtc) figure 5-3. rtc clock generation module clocks kl04 sub-family reference manual, rev. 3.1, november 2012 108 freescale semiconductor, inc.
5.7.4 lptmr clocking the prescaler and glitch filters in each of the lptmr x modules can be clocked as shown in the following figure. note the chosen clock must remain enabled if the lptmr x is to continue operating in all required low-power modes. lptmrx_psr[pcs] lptmrx prescaler/glitch filter clock mcgirclk oscerclk erclk32k lpo sim_sopt1[osc32ksel] osc32kclk rtc_clkin lpo figure 5-4. lptmr x prescaler/glitch filter clock generation 5.7.5 tpm clocking the counter for the tpm modules have a selectable clock as shown in the following figure. note the chosen clock must remain enabled if the tpm x is to continue operating in all required low-power modes. chapter 5 clock distribution kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 109
sim_sopt2[tpmsrc] tpm clock mcgirclk oscerclk mcgfllclk figure 5-5. tpm clock generation 5.7.6 uart clocking the uart0 module has a selectable clock as shown in the following figure. note the chosen clock must remain enabled if the uart0 is to continue operating in all required low-power modes. uart0 clock sim_sopt2[uart0src] mcgfllclk mcgirclk oscerclk figure 5-6. uart0 clock generation module clocks kl04 sub-family reference manual, rev. 3.1, november 2012 110 freescale semiconductor, inc.
chapter 6 reset and boot 6.1 introduction the following reset sources are supported in this mcu: table 6-1. reset sources reset sources description por reset ? power-on reset (por) system resets ? external pin reset (pin) ? low-voltage detect (lvd) ? computer operating properly (cop) watchdog reset ? low leakage wakeup (llwu) reset ? multipurpose clock generator loss of clock (loc) reset ? stop mode acknowledge error (sackerr) ? software reset (sw) ? lockup reset (lockup) ? mdm dap system reset debug reset ? debug reset each of the system reset sources has an associated bit in the system reset status (srs) registers. see the reset control module for register details. the mcu can exit and reset in functional mode where the cpu is executing code (default) or the cpu is in a debug halted state. there are several boot options that can be configured. see boot information for more details. 6.2 reset this section discusses basic reset mechanisms and sources. some modules that cause resets can be configured to cause interrupts instead. consult the individual peripheral chapters for more information. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 111
6.2.1 power-on reset (por) when power is initially applied to the mcu or when the supply voltage drops below the power-on reset re-arm voltage level (v por ), the por circuit causes a por reset condition. as the supply voltage rises, the lvd circuit holds the mcu in reset until the supply has risen above the lvd low threshold (v lvdl ). the por and lvd bits in reset status register are set following a por. 6.2.2 system reset sources resetting the mcu provides a way to start processing from a known set of initial conditions. system reset begins with the on-chip regulator in full regulation and system clocking generation from an internal reference. when the processor exits reset, it performs the following: ? reads the start sp (sp_main) from vector-table offset 0 ? reads the start pc from vector-table offset 4 ? lr is set to 0xffff_ffff the on-chip peripheral modules are disabled and the non-analog i/o pins are initially configured as disabled. the pins with analog functions assigned to them default to their analog function after reset. during and following a reset, the swd pins have their associated input pins configured as: ? swd_clk in pull-down (pd) ? swd_dio in pull-up (pu) 6.2.2.1 external pin reset ( reset) this pin is open drain and has an internal pullup device. asserting reset wakes the device from any mode. the reset pin can be disabled by programming reset_pin_cfg option bit to 0. when this option selected, there could be a short period of contention during a por ramp where the device drives the pin out low prior to establishing the setting of this option and releasing the reset function on the pin. reset kl04 sub-family reference manual, rev. 3.1, november 2012 112 freescale semiconductor, inc.
6.2.2.1.1 reset pin filter the reset pin filter supports filtering from both the 1 khz lpo clock and the bus clock. the rpfc[rstfltss], rpfc[rstfltsrw], and rpfw[rstfltsel] fields in the reset control (rcm) register set control this functionality; see the rcm chapter. the filters are asynchronously reset by chip por. the reset value for each filter assumes the reset pin is negated. for all stop modes where lpo clock is still active (stop, vlps, lls, vlls3, and vlls1), the only filtering option is the lpo based digital filter. the filtering logic either switches to bypass operation or has continued filtering operation depending on the filtering mode selected. when entering vlls0, the reset pin filter is disabled and bypassed. the lpo filter has a fixed filter value of 3. due to a synchronizer on the input data, there is also some associated latency (2 cycles). as a result, 5 cycles are required to complete a transition from low to high or high to low. 6.2.2.2 low-voltage detect (lvd) the chip includes a system for managing low voltage conditions to protect memory contents and control mcu system states during supply voltage variations. the system consists of a power-on reset (por) circuit and an lvd circuit with a user-selectable trip voltage. the lvd system is always enabled in normal run, wait, or stop mode. the lvd system is disabled when entering vlpx, lls, or vllsx modes. the lvd can be configured to generate a reset upon detection of a low voltage condition by setting the pmc's lvdsc1[lvdre] bit to 1. the low voltage detection threshold is determined by the pmc's lvdsc1[lvdv] field. after an lvd reset has occurred, the lvd system holds the mcu in reset until the supply voltage has risen above the low voltage detection threshold. the rcm's srs0[lvd] bit is set following either an lvd reset or por. 6.2.2.3 computer operating properly (cop) watchdog timer the computer operating properly (cop) watchdog timer (wdog) monitors the operation of the system by expecting periodic communication from the software. this communication is generally known as servicing (or refreshing) the cop watchdog. if this periodic refreshing does not occur, the watchdog issues a system reset. the cop reset causes the rcm's srs0[wdog] bit to set. chapter 6 reset and boot kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 113
6.2.2.4 low leakage wakeup (llwu) the llwu module provides the means for a number of external pins and a number of internal peripherals to wake the mcu from low leakage power modes. the llwu module is functional only in low leakage power modes. in vllsx modes, all enabled inputs to the llwu can generate a system reset. after a system reset, the llwu retains the flags indicating the input source of the last wakeup until the user clears them. note some flags are cleared in the llwu and some flags are required to be cleared in the peripheral module. refer to the individual peripheral chapters for more information. 6.2.2.5 multipurpose clock generator loss-of-clock (loc) the mcg module supports an external reference clock. if the c6[cme] bit in the mcg module is set, the clock monitor is enabled. if the external reference falls below f loc_low or f loc_high , as controlled by the c2[range] field in the mcg module, the mcu resets. the rcm's srs0[loc] bit is set to indicate this reset source. note to prevent unexpected loss of clock reset events, all clock monitors must be disabled before entering any low power modes, including vlpr and vlpw. 6.2.2.6 stop mode acknowledge error (sackerr) this reset is generated if the core attempts to enter stop mode or compute operation, but not all modules acknowledge stop mode within 1025 cycles of the 1 khz lpo clock. a module might not acknowledge the entry to stop mode if an error condition occurs. the error can be caused by a failure of an external clock input to a module. reset kl04 sub-family reference manual, rev. 3.1, november 2012 114 freescale semiconductor, inc.
6.2.2.7 software reset (sw) the sysresetreq bit in the nvic application interrupt and reset control register can be set to force a software reset on the device. (see arm's nvic documentation for the full description of the register fields, especially the vectkey field requirements.) setting sysresetreq generates a software reset request. this reset forces a system reset of all major components except for the debug module. a software reset causes the rcm's srs1[sw] bit to set. 6.2.2.8 lockup reset (lockup) the lockup gives immediate indication of seriously errant kernel software. this is the result of the core being locked because of an unrecoverable exception following the activation of the processors built in system state protection hardware. the lockup condition causes a system reset and also causes the rcm's srs1[lockup] bit to set. 6.2.2.9 mdm-ap system reset request set the system reset request bit in the mdm-ap control register to initiate a system reset. this is the primary method for resets via the swd interface. the system reset is held until this bit is cleared. set the core hold reset bit in the mdm-ap control register to hold the core in reset as the rest of the chip comes out of system reset. 6.2.3 mcu resets a variety of resets are generated by the mcu to reset different modules. 6.2.3.1 por only the por only reset asserts on the por reset source only. it resets the pmc and rtc. the por only reset also causes all other reset types to occur. chapter 6 reset and boot kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 115
6.2.3.2 chip por not vlls the chip por not vlls reset asserts on por and lvd reset sources. it resets parts of the smc and sim. it also resets the lptmr. the chip por not vlls reset also causes these resets to occur: chip por, chip reset not vlls, and chip reset (including early chip reset). 6.2.3.3 chip por the chip por asserts on por, lvd, and vlls wakeup reset sources. it resets the reset pin filter registers and parts of the sim and mcg. the chip por also causes the chip reset (including early chip reset) to occur. 6.2.3.4 chip reset not vlls the chip reset not vlls reset asserts on all reset sources except a vlls wakeup that does not occur via the reset pin. it resets parts of the smc, llwu, and other modules that remain powered during vlls mode. the chip reset not vlls reset also causes the chip reset (including early chip reset) to occur. 6.2.3.5 early chip reset the early chip reset asserts on all reset sources. it resets only the flash memory module. it negates before flash memory initialization begins ("earlier" than when the chip reset negates). 6.2.3.6 chip reset chip reset asserts on all reset sources and only negates after flash initialization has completed and the reset pin has also negated. it resets the remaining modules (the modules not reset by other reset types). reset kl04 sub-family reference manual, rev. 3.1, november 2012 116 freescale semiconductor, inc.
6.2.4 reset pin for all reset sources except a vlls wakeup that does not occur via the reset pin, the reset pin is driven low by the mcu for at least 128 bus clock cycles and until flash initialization has completed. after flash initialization has completed, the reset pin is released, and the internal chip reset negates after the reset pin is pulled high. keeping the reset pin asserted externally delays the negation of the internal chip reset. the reset pin can be disabled by programming reset_pin_cfg option bit to 0. when this option is selected, there could be a short period of contention during a por ramp where the device drives the pin out low prior to establishing the setting of this option and releasing the reset function on the pin. 6.2.5 debug resets the following sections detail the debug resets available on the device. 6.2.5.1 resetting the debug subsystem use the cdbgrstreq bit within the dp ctrl/stat register to reset the debug modules. however, as explained below, using the cdbgrstreq bit does not reset all debug-related registers. cdbgrstreq resets the debug-related registers within the following modules: ? sw-dp ? ahb-ap ? mdm-ap (mdm control and status registers) cdbgrstreq does not reset the debug-related registers within the following modules: ? cm0+ core (core debug registers: dhcsr, dcrsr, dcrdr, demcr) ? bpu ? dwt ? nvic ? crossbar bus switch 1 ? ahb-ap 1 ? private peripheral bus 1 1. cdbgrstreq does not affect ahb resources so that debug resources on the private peripheral bus are available during system reset. chapter 6 reset and boot kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 117
6.3 boot this section describes the boot sequence, including sources and options. some configuration information such as clock trim values stored in factory programmed flash locations is autoloaded. 6.3.1 boot sources the cm0+ core adds support for a programmable vector table offset register (vtor) to relocate the exception vector table. this device supports booting from internal flash and ram. this device supports booting from internal flash with the reset vectors located at addresses 0x0 (initial sp_main), 0x4 (initial pc), and ram with relocating the exception vector table to ram. 6.3.2 fopt boot options the flash option register (fopt) in flash memory module (ftfa) allows the user to customize the operation of the mcu at boot time. the register contains read-only bits that are loaded from the nvm's option byte in the flash configuration field. the default setting for all values in the fopt register is logic 1 since it is copied from the option byte residing in flash, which has all bits as logic 1 in the flash erased state. to configure for alternate settings, program the appropriate bits in the nvm option byte. the new settings will take effect on subsequent por, vllsx recoveries, and any system reset. for more details on programming the option byte, refer to the flash memory chapter. the mcu uses the ftfa_fopt register bits to configure the device at reset as shown in the following table. table 6-2. flash option register (ftfa_fopt) bit definitions bit num field value definition 7-6 reserved reserved for future expansion. table continues on the next page... boot kl04 sub-family reference manual, rev. 3.1, november 2012 118 freescale semiconductor, inc.
table 6-2. flash option register (ftfa_fopt) bit definitions (continued) bit num field value definition 5 fast_init select initialization speed on por, vllsx, and any system reset . 0 slower initialization. the flash initialization will be slower with the benefit of reduced average current during this time. the duration of the recovery will be controlled by the clock divider selection determined by the lpboot setting. 1 fast initialization.the flash has faster recoveries at the expense of higher current during these times. 3 reset_pin_cfg enable/disable control for the reset pin. 0 reset pin is disabled following a por and cannot be enabled as reset function. when this option is selected, there could be a short period of contention during a por ramp where the device drives the pin out low prior to establishing the setting of this option and releasing the reset function on the pin. this bit is preserved through system resets and low power modes. when reset pin function is disabled it cannot be used as a source for low power mode wakeup. note: when the reset pin has been disabled and security has been enabled by means of the fsec register, a mass erase can be performed only by setting both the mass erase and system reset request bits in the mdm-ap register. 1 reset pin is dedicated. the port is configured with pullup enabled, open drain, passive filter enabled. 2 nmi_dis enable/disable control for the nmi function. 0 nmi interrupts are always blocked. the associated pin continues to default to nmi pin controls with internal pullup enabled. when nmi pin function is disabled it cannot be used as a source for low power mode wakeup. 1 nmi pin/interrupts reset default to enabled. 1 reserved reserved for future expansion. 4,0 lpboot control the reset value of outdiv1 value in sim_clkdiv1 register. larger divide value selections produce lower average power consumption during por, vllsx recoveries and reset sequencing and after reset exit. the recovery times are also extended if the fast_init option is not selected. 00 core and system clock divider (outdiv1) is 0x7 (divide by 8) 01 core and system clock divider (outdiv1) is 0x3 (divide by 4) 10 core and system clock divider (outdiv1) is 0x1 (divide by 2) 11 core and system clock divider (outdiv1) is 0x0 (divide by 1) 6.3.3 boot sequence at power up, the on-chip regulator holds the system in a por state until the input supply is above the por threshold. the system continues to be held in this static state until the internally regulated supplies have reached a safe operating voltage as determined by the lvd. the reset controller logic then controls a sequence to exit reset. chapter 6 reset and boot kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 119
1. a system reset is held on internal logic, the reset pin is driven out low, and the mcg is enabled in its default clocking mode. 2. required clocks are enabled (system clock, flash clock, and any bus clocks that do not have clock gate control reset to disabled). 3. the system reset on internal logic continues to be held, but the flash controller is released from reset and begins initialization operation while the reset control logic continues to drive the reset pin out low. 4. early in reset sequencing the nvm option byte is read and stored to ftfa_fopt. if the bits associated with lpboot are programmed for an alternate clock divider reset value, the system/core clock is switched to a slower clock speed. if the fast_init bit is programmed clear, the flash initialization switches to slower clock resulting longer recovery times. 5. when flash initialization completes, the reset pin is released. if reset continues to be asserted (an indication of a slow rise time on the reset pin or external drive in low), the system continues to be held in reset. once the reset pin is detected high, the core clock is enabled and the system is released from reset. 6. when the system exits reset, the processor sets up the stack, program counter (pc), and link register (lr). the processor reads the start sp (sp_main) from vector-table offset 0. the core reads the start pc from vector-table offset 4. lr is set to 0xffff_ffff. the cpu begins execution at the pc location. subsequent system resets follow this same reset flow. boot kl04 sub-family reference manual, rev. 3.1, november 2012 120 freescale semiconductor, inc.
chapter 7 power management 7.1 introduction this chapter describes the various chip power modes and functionality of the individual modules in these modes. 7.2 clocking modes this sections describes the various clocking modes supported on this device. 7.2.1 partial stop partial stop is a clocking option that can be taken instead of entering stop mode and is configured in the smc stop control register (smc_stopctrl). the stop mode is only partially entered, which leaves some additional functionality alive at the expense of higher power consumption. partial stop can be entered from either run mode or vlp run mode. when configured for pstop2, only the core and system clocks are gated and the bus clock remains active. the bus masters and bus slaves clocked by the system clock enter stop mode, but the bus slaves clocked by bus clock remain in run (or vlp run) mode. the clock generators in the mcg and the on-chip regulator in the pmc also remain in run (or vlp run) mode. exit from pstop2 can be initiated by a reset, an asynchronous interrupt from a bus master or bus slave clocked by the system clock, or a synchronous interrupt from a bus slave clocked by the bus clock. if configured, a dma request (using the asynchronous dma wakeup) can also be used to exit partial stop for the duration of a dma transfer before the device is transitioned back into pstop2. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 121
when configured for pstop1, both the system clock and bus clock are gated. all bus masters and bus slaves enter stop mode, but the clock generators in the mcg and the on- chip regulator in the pmc remain in run (or vlp run) mode. exit from pstop1 can be initiated by a reset or an asynchronous interrupt from a bus master or bus slave. if configured, an asynchronous dma request can also be used to exit partial stop for the duration of a dma transfer before the device is transitioned back into pstop1. pstop1 is functionally similar to stop mode, but offers faster wakeup at the expense of higher power consumption. another benefit is that it keeps all of the mcg clocks enabled, which can be useful for some of the asynchronous peripherals that can remain functional in stop modes. 7.2.2 dma wakeup the dma can be configured to wakeup the device on a dma request whenever it is placed in stop mode. the wakeup is configured per dma channel and is supported in compute operation, pstop, stop and vlps low power modes. when a dma wakeup is detected in pstop, stop or vlps then the device will initiate a normal exit from the low power mode. this can include restoring the on-chip regulator and internal power switches, enabling the clock generators in the mcg, enabling the system and bus clocks (but not the core clock) and negating the stop mode signal to the bus masters and bus slaves. the only difference is that the cpu will remain in the low power mode with the cpu clock disabled. during compute operation, a dma wakeup will initiate a normal exit from compute operation. this includes enabling the clocks and negating the stop mode signal to the bus masters and bus slaves. the core clock always remains enabled during compute operation. since the dma wakeup will enable the clocks and negate the stop mode signals to all bus masters and slaves, software needs to ensure that bus masters and slaves that are not involved with the dma wakeup and transfer remain in a known state. that can be accomplished by disabling the modules before entry into the low power mode or by setting the doze enable bit in selected modules. once the dma request that initiated the wakeup negates and the dma completes the current transfer, the device will transition back into the original low power mode. this includes requesting all non-cpu bus masters to enter stop mode and then requesting bus slaves to enter stop mode. in stop and vlps modes the mcg and pmc would then also enter their appropriate modes. clocking modes kl04 sub-family reference manual, rev. 3.1, november 2012 122 freescale semiconductor, inc.
note if the requested dma transfer cannot cause the dma request to negate then the device will remain in a higher power state until the low power mode is fully exited. an enabled dma wakeup can cause an aborted entry into the low power mode, if the dma request asserts during the stop mode entry sequence (or reentry if the request asserts during a dma wakeup) and can cause the smc to assert its stop abort flag. once the dma wakeup completes, entry into the low power mode will restart. an interrupt that occurs during a dma wakeup will cause an immediate exit from the low power mode (this is optional for compute operation) without impacting the dma transfer. a dma wakeup can be generated by either a synchronous dma request or an asynchronous dma request. not all peripherals can generate an asynchronous dma request in stop modes, although in general if a peripheral can generate synchronous dma requests and also supports asynchronous interrupts in stop modes, then it can generate an asynchronous dma request. 7.2.3 compute operation compute operation is an execution or compute-only mode of operation that keeps the cpu enabled with full access to the sram and flash read port, but places all other bus masters and bus slaves into their stop mode. compute operation can be enabled in either run mode or vlp run mode. note do not enter any stop mode without first exiting compute operation. because compute operation reuses the stop mode logic (including the staged entry with bus masters disabled before bus slaves), any bus master or bus slave that can remain functional in stop mode also remains functional in compute operation, including generation of asynchronous interrupts and dma requests. when enabling compute operation in run mode, module functionality for bus masters and slaves is the equivalent of stop mode. when enabling compute operation in vlp run mode, module functionality for bus masters and slaves is the equivalent of vlps mode. the mcg, pmc, sram and flash read port are not affected by compute operation, although the flash register interface is disabled. chapter 7 power management kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 123
during compute operation, the aips peripheral space is disabled and attempted accesses generate bus errors. the private peripheral space remains accessible during compute operation, including the mcm, nvic, ioport and systick. although access to the gpio registers via the ioport is supported, the gpio port data input registers do not return valid data since clocks are disabled to the port control and interrupt modules. by writing to the gpio port data output registers, it is possible to control those gpio ports that are configured as output pins. compute operation is controlled by the cpo register in the mcm, which is only accessible to the cpu. setting or clearing the cporeq bit in the mcm initiates entry or exit into compute operation. compute operation can also be configured to exit automatically on detection of an interrupt, which is required in order to service most interrupts. only the core system interrupts (exceptions, including nmi and systick) and any edge sensitive interrupts can be serviced without exiting compute operation. when entering compute operation, the cpoack status bit indicates when entry has completed. when exiting compute operation in run mode, the cpoack status bit negates immediately. when exiting compute operation in vlp run mode, the exit is delayed to allow the pmc to handle the change in power consumption. this delay means the cpoack bit is polled to determine when the aips peripheral space can be accessed without generating a bus error. the dma wakeup is also supported during compute operation and causes the cpoack status bit to clear and the aips peripheral space to be accessible for the duration of the dma wakeup. at the completion of the dma wakeup, the device transitions back into compute operation. 7.2.4 peripheral doze several peripherals support a peripheral doze mode, where a register bit can be used to disable the peripheral for the duration of a low power mode. the flash can also be placed in a low power state during peripheral doze via a register bit in the sim. peripheral doze is defined to include all of the modes of operation listed below. ? the cpu is in wait mode. ? the cpu is in stop mode, including the entry sequence and for the duration of a dma wakeup. ? the cpu is in compute operation, including the entry sequence and for the duration of a dma wakeup. clocking modes kl04 sub-family reference manual, rev. 3.1, november 2012 124 freescale semiconductor, inc.
peripheral doze can therefore be used to disable selected bus masters or slaves for the duration of wait or vlpw mode. it can also be used to disable selected bus slaves immediately on entry into any stop mode (or compute operation), instead of waiting for the bus masters to acknowledge the entry as part of the stop entry sequence. finally, it can be used to disable selected bus masters or slaves that should remain inactive during a dma wakeup. if the flash is not being accessed during wait and pstop modes, then the flash doze mode can be used to reduce power consumption, at the expense of a slightly longer wakeup when executing code and vectors from flash. it can also be used to reduce power consumption during compute operation when executing code and vectors from sram. 7.2.5 clock gating to conserve power, the clocks to most modules can be turned off using the scgcx registers in the sim module. these bits are cleared after any reset, which disables the clock to the corresponding module. prior to initializing a module, set the corresponding bit in the scgcx register to enable the clock. before turning off the clock, make sure to disable the module. for more details, refer to the clock distribution and sim chapters. 7.3 power modes the power management controller (pmc) provides multiple power options to allow the user to optimize power consumption for the level of functionality needed. depending on the stop requirements of the user application, a variety of stop modes are available that provide state retention, partial power down or full power down of certain logic and/or memory. i/o states are held in all modes of operation. the following table compares the various power modes available. for each run mode there is a corresponding wait and stop mode. wait modes are similar to arm sleep modes. stop modes (vlps, stop) are similar to arm sleep deep mode. the very low power run (vlpr) operating mode can drastically reduce runtime power when the maximum bus frequency is not required to handle the application needs. chapter 7 power management kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 125
the three primary modes of operation are run, wait and stop. the wfi instruction invokes both wait and stop modes for the chip. the primary modes are augmented in a number of ways to provide lower power based on application needs. table 7-1. chip power modes chip mode description core mode normal recovery method normal run allows maximum performance of chip. default mode out of reset; on- chip voltage regulator is on. run normal wait - via wfi allows peripherals to function while the core is in sleep mode, reducing power. nvic remains sensitive to interrupts; peripherals continue to be clocked. sleep interrupt normal stop - via wfi places chip in static state. lowest power mode that retains all registers while maintaining lvd protection. nvic is disabled; awic is used to wake up from interrupt; peripheral clocks are stopped. sleep deep interrupt vlpr (very low power run) on-chip voltage regulator is in a low power mode that supplies only enough power to run the chip at a reduced frequency. only mcg modes blpi and blpe can be used in vlpr. reduced frequency flash access mode (1 mhz); lvd off; in blpi clock mode, only the fast internal reference oscillator is available to provide a low power nominal 4mhz source for the core with the nominal bus and flash clock required to be <800khz; alternatively, blpe clock mode can be used with an external clock or the crystal oscillator providing the clock source. run vlpw (very low power wait) -via wfi same as vlpr but with the core in sleep mode to further reduce power; nvic remains sensitive to interrupts (fclk = on). on-chip voltage regulator is in a low power mode that supplies only enough power to run the chip at a reduced frequency. sleep interrupt vlps (very low power stop)-via wfi places chip in static state with lvd operation off. lowest power mode with adc and pin interrupts functional. peripheral clocks are stopped, but osc, lptmr, rtc, cmp can be used. tpm and uart can optionally be enabled if their clock source is enabled. nvic is disabled (fclk = off); awic is used to wake up from interrupt. on-chip voltage regulator is in a low power mode that supplies only enough power to run the chip at a reduced frequency. all sram is operating (content retained and i/o states held). sleep deep interrupt lls (low leakage stop) state retention power mode. most peripherals are in state retention mode (with clocks stopped), but osc, llwu, lptmr, rtc, cmp, can be used. nvic is disabled; llwu is used to wake up. note: the llwu interrupt must not be masked by the interrupt controller to avoid a scenario where the system does not fully exit stop mode on an lls recovery. all sram is operating (content retained and i/o states held). sleep deep wakeup interrupt 1 vlls3 (very low leakage stop3) most peripherals are disabled (with clocks stopped), but osc, llwu, lptmr, rtc, cmp can be used. nvic is disabled; llwu is used to wake up. sram_u and sram_l remain powered on (content retained and i/o states held). sleep deep wakeup reset 2 table continues on the next page... power modes kl04 sub-family reference manual, rev. 3.1, november 2012 126 freescale semiconductor, inc.
table 7-1. chip power modes (continued) chip mode description core mode normal recovery method vlls1 (very low leakage stop1) most peripherals are disabled (with clocks stopped), but osc, llwu, lptmr, rtc, cmp can be used. nvic is disabled; llwu is used to wake up. all of sram_u and sram_l are powered off. sleep deep wakeup reset 2 vlls0 (very low leakage stop 0) most peripherals are disabled (with clocks stopped), but llwu, lptmr, rtc can be used. nvic is disabled; llwu is used to wake up. all of sram_u and sram_l are powered off. lpo disabled, optional por brown-out detection sleep deep wakeup reset 2 1. resumes normal run mode operation by executing the llwu interrupt service routine. 2. follows the reset flow with the llwu interrupt flag set for the nvic. 7.4 entering and exiting power modes the wfi instruction invokes wait and stop modes for the chip. the processor exits the low-power mode via an interrupt. for lls and vlls modes, the wakeup sources are limited to llwu generated wakeups, nmi pin, or reset pin assertions. when the nmi pin or reset pin have been disabled through associated fopt settings, then these pins are ignored as wakeup sources. the wake-up flow from vllsx is always through reset. note the wfe instruction can have the side effect of entering a low- power mode, but that is not its intended usage. see arm documentation for more on the wfe instruction. on vlls recoveries, the i/o pins continue to be held in a static state after code execution begins, allowing software to reconfigure the system before unlocking the i/o. ram is retained in vlls3 only. 7.5 module operation in low power modes the following table illustrates the functionality of each module while the chip is in each of the low power modes. the standard behavior is shown with some exceptions for compute operation (cpo) and partial stop2 (pstop2). chapter 7 power management kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 127
(debug modules are discussed separately; see debug in low power modes .) number ratings (such as 4 mhz and 1 mbps) represent the maximum frequencies or maximum data rates per mode. also, these terms are used: ? ff = full functionality. in vlpr and vlpw the system frequency is limited, but if a module does not have a limitation in its functionality, it is still listed as ff. ? async operation = fully functional with alternate clock source, provided the selected clock source remains enabled ? static = module register states and associated memories are retained. ? powered = memory is powered to retain contents. ? low power = memory is powered to retain contents in a lower power state ? off = modules are powered off; module is in reset state upon wakeup. for clocks, off means disabled. ? wakeup = modules can serve as a wakeup source for the chip. table 7-2. module operation in low power modes modules vlpr vlpw stop vlps lls vllsx core modules nvic ff ff static static static off system modules mode controller ff ff ff ff ff ff llwu 1 static static static static ff ff 2 regulator low power low power on low power low power low power in vlls3, off in vlls0/1 lvd disabled disabled on disabled disabled disabled brown-out detection on on on on on on in vlls1/3, optionally disabled in vlls0 3 dma ff async operation in cpo ff async operation async operation static off watchdog ff static in cpo ff static ff in pstop2 static static off clocks 1khz lpo on on on on on on in vlls1/3, off in vlls0 system oscillator (osc) oscerclk max of 16mhz crystal oscerclk max of 16mhz crystal oscerclk optional oscerclk max of 16mhz crystal limited to low range/low power limited to low range/low power in vlls1/3, off in vlls0 mcg 4 mhz irc 4 mhz irc static - mcgirclk optional static - mcgirclk optional static - no clock output off table continues on the next page... module operation in low power modes kl04 sub-family reference manual, rev. 3.1, november 2012 128 freescale semiconductor, inc.
table 7-2. module operation in low power modes (continued) modules vlpr vlpw stop vlps lls vllsx core clock 4 mhz max off off off off off platform clock 4 mhz max 4 mhz max off off off off system clock 4 mhz max off in cpo 4 mhz max off off off off bus clock 1 mhz max off in cpo 1 mhz max off 24 mhz max in pstop2 from run 1 mhz max in pstop2 from vlpr off off off memory and memory interfaces flash 1 mhz max access - no program no register access in cpo low power low power low power off off sram_u and sram_l low power low power low power low power low power low power in vlls3, off in vlls0/1 communication interfaces uart0 1 mbps async operation in cpo 1 mbps async operation ff in pstop2 async operation static off spi0 master mode 500 kbps, slave mode 250 kbps static, slave mode receive in cpo master mode 500 kbps, slave mode 250 kbps static, slave mode receive ff in pstop2 static, slave mode receive static off i 2 c0 50 kbps static, address match wakeup in cpo 50 kbps static, address match wakeup ff in pstop2 static, address match wakeup static off timers tpm ff async operation in cpo ff async operation ff in pstop2 async operation static off pit ff static in cpo ff static static static off lptmr ff ff async operation ff in pstop2 async operation async operation async operation 4 table continues on the next page... chapter 7 power management kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 129
table 7-2. module operation in low power modes (continued) modules vlpr vlpw stop vlps lls vllsx rtc ff async operation in cpo ff async operation ff in pstop2 async operation async operation async operation 5 analog 12-bit adc ff adc internal clock only in cpo ff adc internal clock only ff in pstop2 adc internal clock only static off cmp 6 ff hs or ls compare in cpo ff hs or ls compare ff in pstop2 hs or ls compare ls compare ls compare in vlls1/3, off in vlls0 6-bit dac ff static in cpo ff static ff in pstop2 static static static, off in vlls0 human-machine interfaces gpio ff ioport write only in cpo ff static output, wakeup input ff in pstop2 static output, wakeup input static, pins latched off, pins latched 1. using the llwu module, the external pins available for this chip do not require the associated peripheral function to be enabled. it only requires the function controlling the pin (gpio or peripheral) to be configured as an input to allow a transition to occur to the llwu. 2. since lpo clock source is disabled, filters will be bypassed during vlls0. 3. the stopctrl[porpo] bit in the smc module controls this option. 4. lpo clock source is not available in vlls0. also, to use system osc in vlls0 it must be configured for bypass (external clock) operation. pulse counting is available in all modes. 5. in vlls0 the only clocking option is from rtc_clkin. 6. cmp in stop or vlps supports high speed or low speed external pin to pin or external pin to dac compares. cmp in lls or vllsx only supports low speed external pin to pin or external pin to dac compares. windowed, sampled & filtered modes of operation are not available while in stop, vlps, lls, or vllsx modes. module operation in low power modes kl04 sub-family reference manual, rev. 3.1, november 2012 130 freescale semiconductor, inc.
chapter 8 security 8.1 introduction this device implements security based on the mode selected from the flash module. the following sections provide an overview of flash security and details the effects of security on non-flash modules. 8.2 flash security the flash module provides security information to the mcu based on the state held by the fsec[sec] bits. the mcu, in turn, confirms the security request and limits access to flash resources. during reset, the flash module initializes the fsec register using data read from the security byte of the flash configuration field. note the security features apply only to external accesses: debug. cpu accesses to the flash are not affected by the status of fsec. in the unsecured state all flash commands are available on the programming interfaces either from the debug port (swd) or user code execution. when the flash is secured (fsec[sec] = 00, 01, or 11), the programmer interfaces are only allowed to launch mass erase operations. additionally, in this mode, the debug port has no access to memory locations. 8.3 security interactions with other modules the flash security settings are used by the system to determine what resources are available. the following sections describe the interactions between modules and the flash security settings or the impact that the flash security has on non-flash modules. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 131
8.3.1 security interactions with debug when flash security is active the swd port cannot access the memory resources of the mcu. although most debug functions are disabled, the debugger can write to the flash mass erase in progress bit to trigger a mass erase (erase all blocks) command. a mass erase via the debugger is allowed even when some memory locations are protected. when mass erase is disabled, mass erase via the debugger is blocked. security interactions with other modules kl04 sub-family reference manual, rev. 3.1, november 2012 132 freescale semiconductor, inc.
chapter 9 debug 9.1 introduction this device's debug is based on the arm coresight tm architecture and is configured to provide the maximum flexibility as allowed by the restrictions of the pinout and other available resources. it provides register and memory accessibility from the external debugger interface, basic run/halt control plus 2 breakpoints and 2 watchpoints. only one debug interface is supported: ? serial wire debug (swd) 9.2 debug port pin descriptions the debug port pins default after por to their swd functionality. table 9-1. serial wire debug pin description pin name type description swd_clk input serial wire clock. this pin is the clock for debug logic when in the serial wire debug mode. this pin is pulled down internally. swd_dio input / output serial wire debug data input/output. the swd_dio pin is used by an external debug tool for communication and device control. this pin is pulled up internally. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 133
9.3 swd status and control registers through the arm debug access port (dap), the debugger has access to the status and control elements, implemented as registers on the dap bus as shown in the following figure. these registers provide additional control and status for low power mode recovery and typical run-control scenarios. the status register bits also provide a means for the debugger to get updated status of the core without having to initiate a bus transaction across the crossbar switch, thus remaining less intrusive during a debug session. it is important to note that these dap control and status registers are not memory mapped within the system memory map and are only accessible via the debug access port using swd. the mdm-ap is accessible as debug access port 1 with the available registers shown in the table below. table 9-2. mdm-ap register summary address register description 0x0100_0000 status see mdm-ap status register 0x0100_0004 control see mdm-ap control register 0x0100_00fc idr read-only identification register that always reads as 0x001c_0020 swd status and control registers kl04 sub-family reference manual, rev. 3.1, november 2012 134 freescale semiconductor, inc.
sw-dp select[31:24] (apsel) selects the ap select[7:4] (apbanksel) selects the bank a[3:2] from the apacc selects the register within the bank ahb access port (ahb - ap) mdm - ap status 0x00 control 0x01 idr 0x3f ahb-ap select[31:24] = 0x00 selects the ahb-ap see arm documentation for further details mdm-ap select[31:24] = 0x01 selects the mdm-ap select[7:4] = 0x0 selects the bank with status and ctrl a[3:2] = 2b00 selects the status register a[3:2] = 2b01 selects the control register select[7:4] = 0xf selects the bank with idr a[3:2] = 2b11 selects the idr register (idr register reads 0x001c_0020) bus matrix see control and status register descriptions debug port internal bus access port data[31:0] a[7:4] a[3:2] rnw apsel decode debug port id register (idcode) control/status (ctrl/stat) ap select (select) read buffer (rdbuff) dp registers 0x00 0x04 0x08 0x0c data[31:0] a[3:2] rnw dpacc data[31:0] a[3:2] rnw apacc debug port (dp) generic see the arm debug interface v5p1 supplement. figure 9-1. mdm ap addressing 9.3.1 mdm-ap control register table 9-3. mdm-ap control register assignments bit name secure 1 description 0 flash mass erase in progress y set to cause mass erase. cleared by hardware after mass erase operation completes. when mass erase is disabled (via meen and sec settings), the erase request does not occur and the flash mass erase in progress bit continues to assert until the next system reset. 1 debug disable n set to disable debug. clear to allow debug operation. when set it overrides the c_debugen bit within the dhcsr and force disables debug logic. table continues on the next page... chapter 9 debug kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 135
table 9-3. mdm-ap control register assignments (continued) bit name secure 1 description 2 debug request n set to force the core to halt. if the core is in a stop or wait mode, this bit can be used to wakeup the core and transition to a halted state. 3 system reset request y set to force a system reset. the system remains held in reset until this bit is cleared. 4 core hold reset n configuration bit to control core operation at the end of system reset sequencing. 0 normal operation - release the core from reset along with the rest of the system at the end of system reset sequencing. 1 suspend operation - hold the core in reset at the end of reset sequencing. once the system enters this suspended state, clearing this control bit immediately releases the core from reset and cpu operation begins. 5 vllsx debug request (vlldbgreq) n set to configure the system to be held in reset after the next recovery from a vllsx mode. this bit is ignored on a vlls wakeup via the reset pin. during a vlls wakeup via the reset pin, the system can be held in reset by holding the reset pin asserted allowing the debugger to re-initialize the debug modules. this bit holds the system in reset when vllsx modes are exited to allow the debugger time to re-initialize debug ip before the debug session continues. the mode controller captures this bit logic on entry to vllsx modes. upon exit from vllsx modes, the mode controller will hold the system in reset until vlldbgack is asserted. the vlldbgreq bit clears automatically due to the por reset generated as part of the vllsx recovery. 6 vllsx debug acknowledge (vlldbgack) n set to release a system being held in reset following a vllsx recovery this bit is used by the debugger to release the system reset when it is being held on vllsx mode exit. the debugger re-initializes all debug ip and then assert this control bit to allow the mode controller to release the system from reset and allow cpu operation to begin. the vlldbgack bit is cleared by the debugger or can be left set because it clears automatically due to the por reset generated as part of the next vllsx recovery. 7 lls, vllsx status acknowledge n set this bit to acknowledge the dap lls and vlls status bits have been read. this acknowledge automatically clears the status bits. this bit is used by the debugger to clear the sticky lls and vllsx mode entry status bits. this bit is asserted and cleared by the debugger. 8 C 31 reserved for future use n 1. command available in secure mode swd status and control registers kl04 sub-family reference manual, rev. 3.1, november 2012 136 freescale semiconductor, inc.
9.3.2 mdm-ap status register table 9-4. mdm-ap status register assignments bit name description 0 flash mass erase acknowledge the flash mass erase acknowledge bit is cleared after any system reset. the bit is also cleared at launch of a mass erase command due to write of flash mass erase in progress bit in mdm ap control register. the flash mass erase acknowledge is set after flash control logic has started the mass erase operation. when mass erase is disabled (via meen and sec settings), an erase request due to seting of flash mass erase in progress bit is not acknowledged. 1 flash ready indicate flash has been initialized and debugger can be configured even if system is continuing to be held in reset via the debugger. 2 system security indicates the security state. when secure, the debugger does not have access to the system bus or any memory mapped peripherals. this bit indicates when the part is locked and no system bus access is possible. 3 system reset indicates the system reset state. 0 system is in reset 1 system is not in reset 4 reserved 5 mass erase enable indicates if the mcu can be mass erased or not 0 mass erase is disabled 1 mass erase is enabled 6 backdoor access key enable indicates if the mcu has the backdoor access key enabled. 0 disabled 1 enabled 7 lp enabled decode of smc_pmctrl[stopm] field to indicate that vlps, lls, or vllsx are the selected power mode the next time the arm core enters deep sleep. 0 low power stop mode is not enabled 1 low power stop mode is enabled usage intended for debug operation in which run to vlps is attempted. per debug definition, the system actually enters the stop state. a debugger should interpret deep sleep indication (with sleepdeep and sleeping asserted), in conjuntion with this bit asserted as the debugger- vlps status indication. 8 very low power mode indicates current power mode is vlpx. this bit is not sticky and should always represent whether vlpx is enabled or not. this bit is used to throttle swd_clk frequency up/down. table continues on the next page... chapter 9 debug kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 137
table 9-4. mdm-ap status register assignments (continued) bit name description 9 lls mode exit this bit indicates an exit from lls mode has occurred. the debugger will lose communication while the system is in lls (including access to this register). once communication is reestablished, this bit indicates that the system had been in lls. since the debug modules held their state during lls, they do not need to be reconfigured. this bit is set during the lls recovery sequence. the lls mode exit bit is held until the debugger has had a chance to recognize that lls was exited and is cleared by a write of 1 to the lls, vllsx status acknowledge bit in mdm ap control register. 10 vllsx modes exit this bit indicates an exit from vllsx mode has occurred. the debugger will lose communication while the system is in vllsx (including access to this register). once communication is reestablished, this bit indicates that the system had been in vllsx. since the debug modules lose their state during vllsx modes, they need to be reconfigured. this bit is set during the vllsx recovery sequence. the vllsx mode exit bit is held until the debugger has had a chance to recognize that a vlls mode was exited and is cleared by a write of 1 to the lls, vllsx status acknowledge bit in mdm ap control register. 11 C 15 reserved for future use always read 0. 16 core halted indicates the core has entered debug halt mode 17 core sleepdeep indicates the core has entered a low power mode sleeping==1 and sleepdeep==0 indicates wait or vlpw mode. sleeping==1 and sleepdeep==1 indicates stop or vlps mode. 18 core sleeping 19 C 31 reserved for future use always read 0. 9.4 debug resets the debug system receives the following sources of reset: ? debug reset (cdbgrstreq bit within the dp ctrl/stat register) that allows the debugger to reset the debug logic. ? system por reset conversely the debug system is capable of generating system reset using the following mechanism: ? a system reset in the dap control register which allows the debugger to hold the system in reset. ? sysresetreq bit in the nvic application interrupt and reset control register ? a system reset in the dap control register which allows the debugger to hold the core in reset. debug resets kl04 sub-family reference manual, rev. 3.1, november 2012 138 freescale semiconductor, inc.
9.5 micro trace buffer (mtb) the micro trace buffer (mtb) provides a simple execution trace capability for the cortex-m0+ processor. when enabled, the mtb records changes in program flow reported by the cortex-m0+ processor, via the execution trace interface, into a configurable region of the sram. subsequently an off-chip debugger may extract the trace information, which would allow reconstruction of an instruction flow trace. the mtb does not include any form of load/store data trace capability or tracing of any other information. in addition to providing the trace capability, the mtb also operates as a simple ahb-lite sram controller. the system bus masters, including the processor, have read/write access to all of the sram via the ahb-lite interface, allowing the memory to also be used to store program and data information. the mtb simultaneously stores the trace information into an attached sram and allows bus masters to access the memory. the mtb ensures that trace information write accesses to the sram take priority over accesses from the ahb-lite interface. the mtb includes trace control registers for configuring and triggering the mtb functions. the mtb also supports triggering via tstart and tstop control functions in the mtb dwt module. 9.6 debug in low power modes in low power modes in which the debug modules are kept static or powered off, the debugger cannot gather any debug data for the duration of the low power mode. in the case that the debugger is held static, the debug port returns to full functionality as soon as the low power mode exits and the system returns to a state with active debug. in the case that the debugger logic is powered off, the debugger is reset on recovery and must be reconfigured once the low power mode is exited. 9.7 debug & security when flash security is enabled, the debug port capabilities are limited in order to prevent exploitation of secure data. in the secure state the debugger still has access to the status register and can determine the current security state of the device. in the case of a secure device, the debugger only has the capability of performing a mass erase operation. chapter 9 debug kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 139
debug & security kl04 sub-family reference manual, rev. 3.1, november 2012 140 freescale semiconductor, inc.
chapter 10 signal multiplexing and signal descriptions 10.1 introduction to optimize functionality in small packages, pins have several functions available via signal multiplexing. this chapter illustrates which of this device's signals are multiplexed on which external pin. the port control block controls which signal is present on the external pin. reference that chapter to find which register controls the operation of a specific pin. 10.2 signal multiplexing integration this section summarizes how the module is integrated into the device. for a comprehensive description of the module itself, see the modules dedicated chapter. register access signal multiplexing/ port control transfers module peripheral bus controller 1 module module external pins transfers figure 10-1. signal multiplexing integration table 10-1. reference links to related information topic related module reference full description port control port control system memory map system memory map table continues on the next page... kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 141
table 10-1. reference links to related information (continued) topic related module reference clocking clock distribution register access peripheral bus controller peripheral bridge 10.2.1 port control and interrupt module features ? 32-pin ports note not all pins are available on the device. see the following section for details. ? each port is assigned one interrupt. ? for dma requests, each port has a dedicated input to the dma mux. the reset state and read/write characteristics of the bit fields within the portx_pcrn registers is summarized in the table below. table 10-2. port control register configuration summary this field of portx_pc rn generally resets to except for resets to configurability ps 1 pta0 0 fixed - all are read only pe 0 pta0 and pta2 1 yes - all gpio are configurable dse 0 no exceptions - all dse are cleared on reset. 4 pins are configurable for high drive (ptb0, ptb1, pta12 and pta13). all are others are fixed for normal drive and the associated dse bit is read only. sre 1 pta2, pta6, pta7, pta15, ptb0, ptb15, ptb16 and ptb17 0 yes - all gpio are configurable mux 000 pta0, pta2 and ptb5 011 yes - all gpio are configurable. msb (bit2) of mux is not writable and always reads 0. pfe 0 no exceptions - all pfe are cleared on reset. 1 the gpio shared with nmi_b pin is configurable. all other gpio is fixed and read only. irqc 000 no exceptions - all are cleared on reset. yes table continues on the next page... signal multiplexing integration kl04 sub-family reference manual, rev. 3.1, november 2012 142 freescale semiconductor, inc.
table 10-2. port control register configuration summary (continued) this field of portx_pc rn generally resets to except for resets to configurability isf 0 no exceptions - all are cleared on reset. 1. the reset pin has the passive analog filter fixed enabled when functioning as the reset pin (fopt[reset_pin_cfg] = 1) and fixed disabled when configured for other shared functions. 10.2.2 clock gating the clock to the port control module can be gated on and off using the scgc5[portx] bits in the sim module. these bits are cleared after any reset, which disables the clock to the corresponding module to conserve power. prior to initializing the corresponding module, set scgc5[portx] in the sim module to enable the clock. before turning off the clock, make sure to disable the module. for more details, refer to the clock distribution chapter. 10.2.3 signal multiplexing constraints 1. a given peripheral function must be assigned to a maximum of one package pin. do not program the same function to more than one pin. 2. to ensure the best signal timing for a given peripheral's interface, choose the pins in closest proximity to each other. pinout 10.3.1 kl04 signal multiplexing and pin assignments the following table shows the signals available on each pin and the locations of these pins on the devices supported by this document. the port control module is responsible for selecting which alt functionality is available on each pin. 48 lqfp 32 qfn 32 lqfp 24 qfn pin name default alt0 alt1 alt2 alt3 1 1 1 1 ptb6/ irq_2/ lptmr0_alt3 disabled disabled ptb6/ irq_2/ lptmr0_alt3 tpm0_ch3 tpm_clkin1 2 2 2 2 ptb7/ irq_3 disabled disabled ptb7/ irq_3 tpm0_ch2 10.3 chapter 10 signal multiplexing and signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 143
48 lqfp 32 qfn 32 lqfp 24 qfn pin name default alt0 alt1 alt2 alt3 3 pta14 disabled disabled pta14 tpm_clkin0 4 pta15 disabled disabled pta15 clkout 5 3 3 3 vdd vdd vdd 6 4 4 3 vrefh vrefh vrefh 7 5 5 4 vrefl vrefl vrefl 8 6 6 4 vss vss vss 9 7 7 5 pta3 extal0 extal0 pta3 i2c0_scl i2c0_sda 10 8 8 6 pta4/ llwu_p0 xtal0 xtal0 pta4/ llwu_p0 i2c0_sda i2c0_scl 11 vss vss vss 12 ptb18 disabled disabled ptb18 13 ptb19 disabled disabled ptb19 14 9 9 7 pta5/ llwu_p1/ rtc_clk_in disabled disabled pta5/ llwu_p1/ rtc_clk_in tpm0_ch5 spi0_ss_b 15 10 10 8 pta6/ llwu_p2 disabled disabled pta6/ llwu_p2 tpm0_ch4 spi0_miso 16 11 11 ptb8 adc0_se11 adc0_se11 ptb8 tpm0_ch3 17 12 12 ptb9 adc0_se10 adc0_se10 ptb9 tpm0_ch2 18 pta16/ irq_4 disabled disabled pta16/ irq_4 19 pta17/ irq_5 disabled disabled pta17/ irq_5 20 pta18/ irq_6 disabled disabled pta18/ irq_6 21 13 13 9 ptb10 adc0_se9 adc0_se9 ptb10 tpm0_ch1 22 14 14 10 ptb11 adc0_se8 adc0_se8 ptb11 tpm0_ch0 23 15 15 11 pta7/ irq_7/ llwu_p3 adc0_se7 adc0_se7 pta7/ irq_7/ llwu_p3 spi0_miso spi0_mosi 24 16 16 12 ptb0/ irq_8/ llwu_p4 adc0_se6 adc0_se6 ptb0/ irq_8/ llwu_p4 extrg_in spi0_sck 25 17 17 13 ptb1/ irq_9 adc0_se5/ cmp0_in3 adc0_se5/ cmp0_in3 ptb1/ irq_9 uart0_tx uart0_rx 26 18 18 14 ptb2/ irq_10/ llwu_p5 adc0_se4 adc0_se4 ptb2/ irq_10/ llwu_p5 uart0_rx uart0_tx 27 19 19 15 pta8 adc0_se3 adc0_se3 pta8 28 20 20 16 pta9 adc0_se2 adc0_se2 pta9 29 ptb20 disabled disabled ptb20 30 vss vss vss 31 vdd vdd vdd 32 ptb14/ irq_11 disabled disabled ptb14/ irq_11 extrg_in pinout kl04 sub-family reference manual, rev. 3.1, november 2012 144 freescale semiconductor, inc.
48 lqfp 32 qfn 32 lqfp 24 qfn pin name default alt0 alt1 alt2 alt3 33 21 21 pta10/ irq_12 disabled disabled pta10/ irq_12 34 22 22 pta11/ irq_13 disabled disabled pta11/ irq_13 35 23 23 17 ptb3/ irq_14 disabled disabled ptb3/ irq_14 i2c0_scl uart0_tx 36 24 24 18 ptb4/ irq_15/ llwu_p6 disabled disabled ptb4/ irq_15/ llwu_p6 i2c0_sda uart0_rx 37 25 25 19 ptb5/ irq_16 nmi_b adc0_se1/ cmp0_in1 ptb5/ irq_16 tpm1_ch1 nmi_b 38 26 26 20 pta12/ irq_17/ lptmr0_alt2 adc0_se0/ cmp0_in0 adc0_se0/ cmp0_in0 pta12/ irq_17/ lptmr0_alt2 tpm1_ch0 tpm_clkin0 39 27 27 pta13 disabled disabled pta13 40 28 28 ptb12 disabled disabled ptb12 41 pta19 disabled disabled pta19 spi0_ss_b 42 ptb15 disabled disabled ptb15 spi0_mosi spi0_miso 43 ptb16 disabled disabled ptb16 spi0_miso spi0_mosi 44 ptb17 disabled disabled ptb17 tpm_clkin1 spi0_sck 45 29 29 21 ptb13 adc0_se13 adc0_se13 ptb13 tpm1_ch1 rtc_clkout 46 30 30 22 pta0/ irq_0/ llwu_p7 swd_clk adc0_se12/ cmp0_in2 pta0/ irq_0/ llwu_p7 tpm1_ch0 swd_clk 47 31 31 23 pta1/ irq_1/ lptmr0_alt1 reset_b disabled pta1/ irq_1/ lptmr0_alt1 tpm_clkin0 reset_b 48 32 32 24 pta2 swd_dio disabled pta2 cmp0_out swd_dio 10.3.2 kl04 pinouts the following figures show the pinout diagrams for the devices supported by this document. many signals may be multiplexed onto a single pin. to determine what signals can be used on which pin, see the previous section. chapter 10 signal multiplexing and signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 145
ptb18 vss pta4/llwu_p0 pta3 vss vrefl vrefh vdd pta15 pta14 ptb7/irq_3 ptb6/irq_2/lptmr0_alt3 12 11 10 9 8 7 6 5 4 3 2 1 48 47 46 45 44 43 42 41 40 39 38 37 pta2 pta1/irq_1/lptmr0_alt1 pta0/irq_0/llwu_p7 ptb13 ptb17 ptb16 ptb15 pta19 ptb12 pta13 pta12/irq_17/lptmr0_alt2 ptb5/irq_16 36 35 34 33 ptb4/irq_15/llwu_p6 ptb3/irq_14 pta11/irq_13 pta10/irq_12 32 31 30 29 28 27 26 25 ptb14/irq_11 vdd vss ptb20 pta9 pta8 ptb2/irq_10/llwu_p5 ptb1/irq_9 pta18/irq_6 pta17/irq_5 pta16/irq_4 ptb9 24 23 22 21 20 19 18 17 ptb8 pta6/llwu_p2 pta5/llwu_p1/rtc_clk_in ptb19 16 15 14 13 ptb0/irq_8/llwu_p4 pta7/irq_7/llwu_p3 ptb11 ptb10 figure 10-2. kl04 48-pin lqfp pinout diagram pinout kl04 sub-family reference manual, rev. 3.1, november 2012 146 freescale semiconductor, inc.
32 31 30 29 28 27 26 25 pta2 pta1/irq_1/lptmr0_alt1 pta0/irq_0/llwu_p7 ptb13 ptb12 pta13 pta12/irq_17/lptmr0_alt2 ptb5/irq_16 ptb9 ptb8 pta6/llwu_p2 pta5/llwu_p1/rtc_clk_in 12 11 10 9 ptb0/irq_8/llwu_p4 pta7/irq_7/llwu_p3 ptb11 ptb10 16 15 14 13 pta9 pta8 ptb2/irq_10/llwu_p5 ptb1/irq_9 24 23 22 21 20 19 18 17 ptb4/irq_15/llwu_p6 ptb3/irq_14 pta11/irq_13 pta10/irq_12 pta4/llwu_p0 pta3 vss vrefl vrefh vdd ptb7/irq_3 ptb6/irq_2/lptmr0_alt3 8 7 6 5 4 3 2 1 figure 10-3. kl04 32-pin lqfp pinout diagram chapter 10 signal multiplexing and signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 147
32 31 30 29 28 27 26 25 pta2 pta1/irq_1/lptmr0_alt1 pta0/irq_0/llwu_p7 ptb13 ptb12 pta13 pta12/irq_17/lptmr0_alt2 ptb5/irq_16 ptb9 ptb8 pta6/llwu_p2 pta5/llwu_p1/rtc_clk_in 12 11 10 9 ptb0/irq_8/llwu_p4 pta7/irq_7/llwu_p3 ptb11 ptb10 16 15 14 13 pta9 pta8 ptb2/irq_10/llwu_p5 ptb1/irq_9 24 23 22 21 20 19 18 17 ptb4/irq_15/llwu_p6 ptb3/irq_14 pta11/irq_13 pta10/irq_12 pta4/llwu_p0 pta3 vss vrefl vrefh vdd ptb7/irq_3 ptb6/irq_2/lptmr0_alt3 8 7 6 5 4 3 2 1 figure 10-4. kl04 32-pin qfn pinout diagram pinout kl04 sub-family reference manual, rev. 3.1, november 2012 148 freescale semiconductor, inc.
24 23 22 pta2 pta1/irq_1/lptmr0_alt1 pta0/irq_0/llwu_p7 pta12/irq_17/lptmr0_alt2 ptb5/irq_16 21 20 19 ptb13 pta9 pta8 16 15 ptb4/irq_15/llwu_p6 ptb3/irq_14 18 17 ptb2/irq_10/llwu_p5 ptb1/irq_9 14 13 ptb0/irq_8/llwu_p4 pta7/irq_7/llwu_p3 ptb11 ptb10 12 11 10 9 pta6/llwu_p2 8 pta5/llwu_p1/rtc_clk_in 7 pta4/llwu_p0 pta3 vrefl vss vdd vrefh ptb7/irq_3 ptb6/irq_2/lptmr0_alt3 6 5 4 3 2 1 figure 10-5. kl04 24-pin qfn pinout diagram 10.4 module signal description tables the following sections correlate the chip-level signal name with the signal name used in the module's chapter. they also briefly describe the signal function and direction. 10.4.1 core modules table 10-3. swd signal descriptions chip signal name module signal name description i/o swd_dio swd_dio serial wire debug data input/output. the swd_dio pin is used by an external debug tool for communication and device control. this pin is pulled up internally. input / output table continues on the next page... chapter 10 signal multiplexing and signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 149
table 10-3. swd signal descriptions (continued) chip signal name module signal name description i/o swd_clk swd_clk serial wire clock. this pin is the clock for debug logic when in the serial wire debug mode. this pin is pulled down internally. input 10.4.2 system modules table 10-4. system signal descriptions chip signal name module signal name description i/o nmi non-maskable interrupt note: driving the nmi signal low forces a non-maskable interrupt, if the nmi function is selected on the corresponding pin. i reset reset bi-directional signal i/o vdd mcu power i vss mcu ground i 10.4.3 clock modules table 10-5. osc signal descriptions chip signal name module signal name description i/o extal0 extal external clock/oscillator input i xtal0 xtal oscillator output o 10.4.4 memories and memory interfaces module signal description tables kl04 sub-family reference manual, rev. 3.1, november 2012 150 freescale semiconductor, inc.
10.4.5 analog table 10-6. adc 0 signal descriptions chip signal name module signal name description i/o adc0_sen ad n single-ended analog channel inputs i vrefh v refsh voltage reference select high i vrefl v refsl voltage reference select low i vdda v dda analog power supply i vssa v ssa analog ground i table 10-7. cmp 0 signal descriptions chip signal name module signal name description i/o cmp0_in[5:0] in[5:0] analog voltage inputs i cmp0_out cmpo comparator output o 10.4.6 timer modules table 10-8. tpm 0 signal descriptions chip signal name module signal name description i/o tpm_clkin[1:0] extclk external clock. ftm external clock can be selected to drive the ftm counter. i tpm0_ch[5:0] chn ftm channel (n), where n can be 7-0 i/o table 10-9. tpm 1 signal descriptions chip signal name module signal name description i/o tpm_clkin[1:0] tpm_extclk external clock. tpm external clock can be selected to increment the tpm counter on every rising edge synchronized to the counter clock. i tpm1_ch[1:0] tpm_chn tpm channel (n = 5 to 0) i/o table 10-10. lptmr 0 signal descriptions chip signal name module signal name description i/o lptmr0_alt[2:1] lptmr_alt n pulse counter input pin i chapter 10 signal multiplexing and signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 151
table 10-11. rtc signal descriptions chip signal name module signal name description i/o rtc_clkout 1 rtc_clkout 1 hz square-wave output o 1. rtc_clkout can also be driven with oscerclk via sim control bit sim_sopt[rctclkoutsel] 10.4.7 communication interfaces table 10-12. spi0 signal descriptions chip signal name module signal name description i/o spi0_miso miso master data in, slave data out i/o spi0_mosi mosi master data out, slave data in i/o spi0_sclk spsck spi serial clock i/o spi0_pcs0 ss slave select i/o table 10-13. i 2 c 0 signal descriptions chip signal name module signal name description i/o i2c0_scl scl bidirectional serial clock line of the i 2 c system. i/o i2c0_sda sda bidirectional serial data line of the i 2 c system. i/o table 10-14. uart 0 signal descriptions chip signal name module signal name description i/o uart0_tx txd transmit data o uart0_rx rxd receive data i 10.4.8 human-machine interfaces (hmi) table 10-15. gpio signal descriptions chip signal name module signal name description i/o pta[31:0] 1 porta31Cporta0 general-purpose input/output i/o ptb[31:0] 1 portb31Cportb0 general-purpose input/output i/o 1. the available gpio pins depends on the specific package. see the signal multiplexing section for which exact gpio signals are available. module signal description tables kl04 sub-family reference manual, rev. 3.1, november 2012 152 freescale semiconductor, inc.
chapter 11 port control and interrupts (port) 11.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. 11.2 overview the port control and interrupt (port) module provides support for port control, and external interrupt functions. most functions can be configured independently for each pin in the 32-bit port and affect the pin regardless of its pin muxing state. there is one instance of the port module for each port. not all pins within each port are implemented on a specific device. 11.2.1 features the port module has the following features: ? pin interrupt on selected pins ? interrupt flag and enable registers for each pin ? support for edge sensitive (rising, falling, both) or level sensitive (low, high) configured per pin ? support for interrupt or dma request configured per pin ? asynchronous wakeup in low-power modes ? pin interrupt is functional in all digital pin muxing modes ? port control kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 153
? individual pull control fields with pullup, pulldown, and pull-disablesupport on selected pins ? individual drive strength field supporting high and low drive strength on selected pins ? individual slew rate field supporting fast and slow slew rates on selected pins ? individual input passive filter field supporting enable and disable of the individual input passive filter on selected pins ? individual mux control field supporting analog or pin disabled, gpio, and up to four chip-specific digital functions ? pad configuration fields are functional in all digital pin muxing modes 11.2.2 modes of operation 11.2.2.1 run mode in run mode, the port operates normally. 11.2.2.2 wait mode in wait mode, port continues to operate normally and may be configured to exit the low-power mode if an enabled interrupt is detected. dma requests are still generated during the wait mode, but do not cause an exit from the low-power mode. 11.2.2.3 stop mode in stop mode, the port can be configured to exit the low-power mode via an asynchronous wakeup signal if an enabled interrupt is detected. 11.2.2.4 debug mode in debug mode, port operates normally. 11.3 external signal description the following table describes the port external signal. external signal description kl04 sub-family reference manual, rev. 3.1, november 2012 154 freescale semiconductor, inc.
table 11-1. signal properties name function i/o reset pull portx[31:0] external interrupt i/o 0 - note not all pins within each port are implemented on each device. 11.4 detailed signal description the following table contains the detailed signal description for the port interface. table 11-2. port interfacedetailed signal description signal i/o description portx[31:0] i/o external interrupt. state meaning assertedpin is logic one. negatedpin is logic zero. timing assertionmay occur at any time and can assert asynchronously to the system clock. negationmay occur at any time and can assert asynchronously to the system clock. 11.5 memory map and register definition any read or write access to the port memory space that is outside the valid memory map results in a bus error. all register accesses complete with zero wait states. port memory map absolute address (hex) register name width (in bits) access reset value section/ page 4004_9000 pin control register n (porta_pcr0) 32 r/w see section 11.5.1/158 4004_9004 pin control register n (porta_pcr1) 32 r/w see section 11.5.1/158 4004_9008 pin control register n (porta_pcr2) 32 r/w see section 11.5.1/158 4004_900c pin control register n (porta_pcr3) 32 r/w see section 11.5.1/158 4004_9010 pin control register n (porta_pcr4) 32 r/w see section 11.5.1/158 4004_9014 pin control register n (porta_pcr5) 32 r/w see section 11.5.1/158 4004_9018 pin control register n (porta_pcr6) 32 r/w see section 11.5.1/158 4004_901c pin control register n (porta_pcr7) 32 r/w see section 11.5.1/158 table continues on the next page... chapter 11 port control and interrupts (port) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 155
port memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page 4004_9020 pin control register n (porta_pcr8) 32 r/w see section 11.5.1/158 4004_9024 pin control register n (porta_pcr9) 32 r/w see section 11.5.1/158 4004_9028 pin control register n (porta_pcr10) 32 r/w see section 11.5.1/158 4004_902c pin control register n (porta_pcr11) 32 r/w see section 11.5.1/158 4004_9030 pin control register n (porta_pcr12) 32 r/w see section 11.5.1/158 4004_9034 pin control register n (porta_pcr13) 32 r/w see section 11.5.1/158 4004_9038 pin control register n (porta_pcr14) 32 r/w see section 11.5.1/158 4004_903c pin control register n (porta_pcr15) 32 r/w see section 11.5.1/158 4004_9040 pin control register n (porta_pcr16) 32 r/w see section 11.5.1/158 4004_9044 pin control register n (porta_pcr17) 32 r/w see section 11.5.1/158 4004_9048 pin control register n (porta_pcr18) 32 r/w see section 11.5.1/158 4004_904c pin control register n (porta_pcr19) 32 r/w see section 11.5.1/158 4004_9050 pin control register n (porta_pcr20) 32 r/w see section 11.5.1/158 4004_9054 pin control register n (porta_pcr21) 32 r/w see section 11.5.1/158 4004_9058 pin control register n (porta_pcr22) 32 r/w see section 11.5.1/158 4004_905c pin control register n (porta_pcr23) 32 r/w see section 11.5.1/158 4004_9060 pin control register n (porta_pcr24) 32 r/w see section 11.5.1/158 4004_9064 pin control register n (porta_pcr25) 32 r/w see section 11.5.1/158 4004_9068 pin control register n (porta_pcr26) 32 r/w see section 11.5.1/158 4004_906c pin control register n (porta_pcr27) 32 r/w see section 11.5.1/158 4004_9070 pin control register n (porta_pcr28) 32 r/w see section 11.5.1/158 4004_9074 pin control register n (porta_pcr29) 32 r/w see section 11.5.1/158 4004_9078 pin control register n (porta_pcr30) 32 r/w see section 11.5.1/158 4004_907c pin control register n (porta_pcr31) 32 r/w see section 11.5.1/158 4004_9080 global pin control low register (porta_gpclr) 32 w (always reads 0) 0000_0000h 11.5.2/160 4004_9084 global pin control high register (porta_gpchr) 32 w (always reads 0) 0000_0000h 11.5.3/161 4004_90a0 interrupt status flag register (porta_isfr) 32 w1c 0000_0000h 11.5.4/161 4004_a000 pin control register n (portb_pcr0) 32 r/w see section 11.5.1/158 4004_a004 pin control register n (portb_pcr1) 32 r/w see section 11.5.1/158 4004_a008 pin control register n (portb_pcr2) 32 r/w see section 11.5.1/158 4004_a00c pin control register n (portb_pcr3) 32 r/w see section 11.5.1/158 4004_a010 pin control register n (portb_pcr4) 32 r/w see section 11.5.1/158 4004_a014 pin control register n (portb_pcr5) 32 r/w see section 11.5.1/158 4004_a018 pin control register n (portb_pcr6) 32 r/w see section 11.5.1/158 4004_a01c pin control register n (portb_pcr7) 32 r/w see section 11.5.1/158 table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 156 freescale semiconductor, inc.
port memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page 4004_a020 pin control register n (portb_pcr8) 32 r/w see section 11.5.1/158 4004_a024 pin control register n (portb_pcr9) 32 r/w see section 11.5.1/158 4004_a028 pin control register n (portb_pcr10) 32 r/w see section 11.5.1/158 4004_a02c pin control register n (portb_pcr11) 32 r/w see section 11.5.1/158 4004_a030 pin control register n (portb_pcr12) 32 r/w see section 11.5.1/158 4004_a034 pin control register n (portb_pcr13) 32 r/w see section 11.5.1/158 4004_a038 pin control register n (portb_pcr14) 32 r/w see section 11.5.1/158 4004_a03c pin control register n (portb_pcr15) 32 r/w see section 11.5.1/158 4004_a040 pin control register n (portb_pcr16) 32 r/w see section 11.5.1/158 4004_a044 pin control register n (portb_pcr17) 32 r/w see section 11.5.1/158 4004_a048 pin control register n (portb_pcr18) 32 r/w see section 11.5.1/158 4004_a04c pin control register n (portb_pcr19) 32 r/w see section 11.5.1/158 4004_a050 pin control register n (portb_pcr20) 32 r/w see section 11.5.1/158 4004_a054 pin control register n (portb_pcr21) 32 r/w see section 11.5.1/158 4004_a058 pin control register n (portb_pcr22) 32 r/w see section 11.5.1/158 4004_a05c pin control register n (portb_pcr23) 32 r/w see section 11.5.1/158 4004_a060 pin control register n (portb_pcr24) 32 r/w see section 11.5.1/158 4004_a064 pin control register n (portb_pcr25) 32 r/w see section 11.5.1/158 4004_a068 pin control register n (portb_pcr26) 32 r/w see section 11.5.1/158 4004_a06c pin control register n (portb_pcr27) 32 r/w see section 11.5.1/158 4004_a070 pin control register n (portb_pcr28) 32 r/w see section 11.5.1/158 4004_a074 pin control register n (portb_pcr29) 32 r/w see section 11.5.1/158 4004_a078 pin control register n (portb_pcr30) 32 r/w see section 11.5.1/158 4004_a07c pin control register n (portb_pcr31) 32 r/w see section 11.5.1/158 4004_a080 global pin control low register (portb_gpclr) 32 w (always reads 0) 0000_0000h 11.5.2/160 4004_a084 global pin control high register (portb_gpchr) 32 w (always reads 0) 0000_0000h 11.5.3/161 4004_a0a0 interrupt status flag register (portb_isfr) 32 w1c 0000_0000h 11.5.4/161 chapter 11 port control and interrupts (port) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 157
11.5.1 pin control register n (port x _pcr n ) note refer to the signal multiplexing and pin assignment chapter for the reset value of this device. see the gpio configuration section for details on the available functions for each pin. do not modify pin configuration registers associated with pins not available in your selected package. all un-bonded pins not available in your package will default to disable state for lowest power consumption. address: base address + 0h offset + (4d i), where i=0d to 31d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 isf 0 irqc w w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 mux 0 dse 0 pfe 0 sre pe ps w reset 0 0 0 0 0 * * * 0 * 0 * 0 * * * * notes: mux field: varies by port. see signal multiplexing and signal descriptions chapter for reset values per port. ? dse field: varies by port. see signal multiplexing and signal descriptions chapter for reset values per port. ? pfe field: varies by port. see signal multiplexing and signal descriptions chapter for reset values per port. ? sre field: varies by port. see signal multiplexing and signal descriptions chapter for reset values per port. ? pe field: varies by port. see signal multiplexing and signal descriptions chapter for reset values per port. ? ps field: varies by port. see signal multiplexing and signal descriptions chapter for reset values per port. ? port x _pcr n field descriptions field description 31C25 reserved this field is reserved. this read-only field is reserved and always has the value 0. 24 isf interrupt status flag this bit is read only for pins that do not support interrupt generation. the pin interrupt configuration is valid in all digital pin muxing modes. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 158 freescale semiconductor, inc.
port x _pcr n field descriptions (continued) field description 0 configured interrupt is not detected. 1 configured interrupt is detected. if the pin is configured to generate a dma request, then the corresponding flag will be cleared automatically at the completion of the requested dma transfer. otherwise, the flag remains set until a logic one is written to the flag. if the pin is configured for a level sensitive interrupt and the pin remains asserted, then the flag is set again immediately after it is cleared. 23C20 reserved this field is reserved. this read-only field is reserved and always has the value 0. 19C16 irqc interrupt configuration this field is read only for pins that do not support interrupt generation. the pin interrupt configuration is valid in all digital pin muxing modes. the corresponding pin is configured to generate interrupt/dma request as follows: 0000 interrupt/dma request disabled. 0001 dma request on rising edge. 0010 dma request on falling edge. 0011 dma request on either edge. 1000 interrupt when logic zero. 1001 interrupt on rising edge. 1010 interrupt on falling edge. 1011 interrupt on either edge. 1100 interrupt when logic one. others reserved. 15C11 reserved this field is reserved. this read-only field is reserved and always has the value 0. 10C8 mux pin mux control not all pins support all pin muxing slots. unimplemented pin muxing slots are reserved and may result in configuring the pin for a different pin muxing slot. the corresponding pin is configured in the following pin muxing slot as follows: 000 pin disabled (analog). 001 alternative 1 (gpio). 010 alternative 2 (chip-specific). 011 alternative 3 (chip-specific). 100 alternative 4 (chip-specific). 101 alternative 5 (chip-specific). 110 alternative 6 (chip-specific). 111 alternative 7 (chip-specific). 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6 dse drive strength enable this bit is read only for pins that do not support a configurable drive strength. drive strength configuration is valid in all digital pin muxing modes. 0 low drive strength is configured on the corresponding pin, if pin is configured as a digital output. 1 high drive strength is configured on the corresponding pin, if pin is configured as a digital output. table continues on the next page... chapter 11 port control and interrupts (port) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 159
port x _pcr n field descriptions (continued) field description 5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4 pfe passive filter enable this bit is read only for pins that do not support a configurable passive input filter. passive filter configuration is valid in all digital pin muxing modes. 0 passive input filter is disabled on the corresponding pin. 1 passive input filter is enabled on the corresponding pin, if the pin is configured as a digital input. refer to the device data sheet for filter characteristics. 3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 sre slew rate enable this bit is read only for pins that do not support a configurable slew rate. slew rate configuration is valid in all digital pin muxing modes. 0 fast slew rate is configured on the corresponding pin, if the pin is configured as a digital output. 1 slow slew rate is configured on the corresponding pin, if the pin is configured as a digital output. 1 pe pull enable this bit is read only for pins that do not support a configurable pull resistor. refer to the chapter of signal multiplexing and signal descriptions for the pins that support a configurable pull resistor. pull configuration is valid in all digital pin muxing modes. 0 internal pullup or pulldown resistor is not enabled on the corresponding pin. 1 internal pullup or pulldown resistor is enabled on the corresponding pin, if the pin is configured as a digital input. 0 ps pull select this bit is read only for pins that do not support a configurable pull resistor direction. pull configuration is valid in all digital pin muxing modes. 0 internal pulldown resistor is enabled on the corresponding pin, if the corresponding port pull enable field is set. 1 internal pullup resistor is enabled on the corresponding pin, if the corresponding port pull enable field is set. 11.5.2 global pin control low register (port x _gpclr) only 32-bit writes are supported to this register. address: base address + 80h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 w gpwe gpwd reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 160 freescale semiconductor, inc.
port x _gpclr field descriptions field description 31C16 gpwe global pin write enable selects which pin control registers (15 through 0) bits [15:0] update with the value in gpwd. 0 corresponding pin control register is not updated with the value in gpwd. 1 corresponding pin control register is updated with the value in gpwd. 15C0 gpwd global pin write data write value that is written to all pin control registers bits [15:0] that are selected by gpwe. 11.5.3 global pin control high register (port x _gpchr) only 32-bit writes are supported to this register. address: base address + 84h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 w gpwe gpwd reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 port x _gpchr field descriptions field description 31C16 gpwe global pin write enable selects which pin control registers (31 through 16) bits [15:0] update with the value in gpwd. 0 corresponding pin control register is not updated with the value in gpwd. 1 corresponding pin control register is updated with the value in gpwd. 15C0 gpwd global pin write data write value that is written to all pin control registers bits [15:0] that are selected by gpwe. 11.5.4 interrupt status flag register (port x _isfr) the corresponding bit is read only for pins that do not support interrupt generation. the pin interrupt configuration is valid in all digital pin muxing modes. the interrupt status flag for each pin is also visible in the corresponding pin control register, and each flag can be cleared in either location. chapter 11 port control and interrupts (port) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 161
address: base address + a0h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r isf w w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 port x _isfr field descriptions field description 31C0 isf interrupt status flag each bit in the field indicates the detection of the configured interrupt of the same number as the field. 0 configured interrupt is not detected. 1 configured interrupt is detected. if the pin is configured to generate a dma request, then the corresponding flag will be cleared automatically at the completion of the requested dma transfer. otherwise, the flag remains set until a logic one is written to the flag. if the pin is configured for a level sensitive interrupt and the pin remains asserted, then the flag is set again immediately after it is cleared. 11.6 functional description 11.6.1 pin control each port pin has a corresponding pin control register, port_pcrn, associated with it. the upper half of the pin control register configures the pin's capability to either interrupt the cpu or request a dma transfer, on a rising/falling edge or both edges as well as a logic level occurring on the port pin. it also includes a flag to indicate that an interrupt has occurred. the lower half of the pin control register configures the following functions for each pin within the 32-bit port. ? pullup or pulldown enable on selected pins ? drive strength and slew rate configuration on selected pins ? passive input filter enable on selected pins ? pin muxing mode the functions apply across all digital pin muxing modes and individual peripherals do not override the configuration in the pin control register. for example, if an i 2 c function is enabled on a pin, that does not override the pullup configuration for that pin. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 162 freescale semiconductor, inc.
when the pin muxing mode is configured for analog or is disabled, all the digital functions on that pin are disabled. this includes the pullup and pulldown enables, and passive filter enable. the configuration of each pin control register is retained when the port module is disabled. 11.6.2 global pin control the two global pin control registers allow a single register write to update the lower half of the pin control register on up to sixteen pins, all with the same value. the global pin control registers are designed to enable software to quickly configure multiple pins within the one port for the same peripheral function. however, the interrupt functions cannot be configured using the global pin control registers. the global pin control registers are write-only registers, that always read as zero. 11.6.3 external interrupts the external interrupt capability of the port module is available in all digital pin muxing modes provided the port module is enabled. each pin can be individually configured for any of the following external interrupt modes: ? interrupt disabled, default out of reset ? active high level sensitive interrupt ? active low level sensitive interrupt ? rising edge sensitive interrupt ? falling edge sensitive interrupt ? rising and falling edge sensitive interrupt ? rising edge sensitive dma request ? falling edge sensitive dma request ? rising and falling edge sensitive dma request the interrupt status flag is set when the configured edge or level is detected on the output of the pin. when not in stop mode, the input is first synchronized to the bus clock to detect the configured level or edge transition. chapter 11 port control and interrupts (port) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 163
the port module generates a single interrupt that asserts when the interrupt status flag is set for any enabled interrupt for that port. the interrupt negates after the interrupt status flags for all enabled interrupts have been cleared by writing a logic 1 to the isf flag in either the port_isfr or port_pcrn registers. the port module generates a single dma request that asserts when the interrupt status flag is set for any enabled dma request in that port. the dma request negates after the dma transfer is completed, because that clears the interrupt status flags for all enabled dma requests. during stop mode, the interrupt status flag for any enabled interrupt is asynchronously set if the required level or edge is detected. this also generates an asynchronous wakeup signal to exit the low-power mode. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 164 freescale semiconductor, inc.
chapter 12 system integration module (sim) 12.1 introduction the system integration module (sim) provides system control and chip configuration registers. 12.1.1 features ? system clocking configuration ? system clock divide values ? architectural clock gating control ? erclk32k clock selection ? uart0 and tpm clock selection ? flash and system ram size configuration ? tpm external clock and input capture selection ? uart receive/transmit source selection/configuration 12.2 memory map and register definition the sim module contains many bitfields for selecting the clock source and dividers for various module clocks. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 165
note the sim registers can be written only in supervisor mode. in user mode, write accesses are blocked and will result in a bus error. note the sim_sopt1 and sim_sopt1cfg registers are located at a different base address than the other sim registers. sim memory map absolute address (hex) register name width (in bits) access reset value section/ page 4004_7000 system options register 1 (sim_sopt1) 32 r/w 0000_0000h 12.2.1/167 4004_7004 sopt1 configuration register (sim_sopt1cfg) 32 r/w 0000_0000h 12.2.2/167 4004_8004 system options register 2 (sim_sopt2) 32 r/w 0000_0000h 12.2.3/168 4004_800c system options register 4 (sim_sopt4) 32 r/w 0000_0000h 12.2.4/170 4004_8010 system options register 5 (sim_sopt5) 32 r/w 0000_0000h 12.2.5/171 4004_8018 system options register 7 (sim_sopt7) 32 r/w 0000_0000h 12.2.6/172 4004_8024 system device identification register (sim_sdid) 32 r see section 12.2.7/174 4004_8034 system clock gating control register 4 (sim_scgc4) 32 r/w f000_0030h 12.2.8/176 4004_8038 system clock gating control register 5 (sim_scgc5) 32 r/w 0000_0180h 12.2.9/177 4004_803c system clock gating control register 6 (sim_scgc6) 32 r/w 0000_0001h 12.2.10/179 4004_8040 system clock gating control register 7 (sim_scgc7) 32 r/w 0000_0100h 12.2.11/180 4004_8044 system clock divider register 1 (sim_clkdiv1) 32 r/w see section 12.2.12/181 4004_804c flash configuration register 1 (sim_fcfg1) 32 r/w see section 12.2.13/183 4004_8050 flash configuration register 2 (sim_fcfg2) 32 r see section 12.2.14/184 4004_8058 unique identification register mid-high (sim_uidmh) 32 r see section 12.2.15/185 4004_805c unique identification register mid low (sim_uidml) 32 r see section 12.2.16/185 4004_8060 unique identification register low (sim_uidl) 32 r see section 12.2.17/186 4004_8100 cop control register (sim_copc) 32 r/w 0000_000ch 12.2.18/186 4004_8104 service cop register (sim_srvcop) 32 w 0000_0000h 12.2.19/187 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 166 freescale semiconductor, inc.
12.2.1 system options register 1 (sim_sopt1) note the sopt1 register is only reset on por or lvd. address: 4004_7000h base + 0h offset = 4004_7000h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 osc32ksel 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 sim_sopt1 field descriptions field description 31C20 reserved this field is reserved. this read-only field is reserved and always has the value 0. 19C18 osc32ksel 32k oscillator clock select selects the 32 khz clock source (erclk32k) for rtc and lptmr. this bit is reset only on por/lvd. 00 system oscillator (osc32kclk) 01 reserved 10 rtc_clkin 11 lpo 1khz 17C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 12.2.2 sopt1 configuration register (sim_sopt1cfg) note the sopt1cfg register is reset on system reset not vlls. address: 4004_7000h base + 4h offset = 4004_7004h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 167
sim_sopt1cfg field descriptions field description 31C24 reserved this field is reserved. this read-only field is reserved and always has the value 0. 23C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 12.2.3 system options register 2 (sim_sopt2) sopt2 contains the controls for selecting many of the module clock source options on this device. see the clock distribution chapter for more information including clocking diagrams and definitions of device clocks. address: 4004_7000h base + 1004h offset = 4004_8004h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 uart0src tpmsrc 0 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clkoutsel rtcclkouts el 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 sim_sopt2 field descriptions field description 31C28 reserved this field is reserved. this read-only field is reserved and always has the value 0. 27C26 uart0src uart0 clock source select selects the clock source for the uart0 transmit and receive clock. 00 clock disabled 01 mcgfllclk clock 10 oscerclk clock 11 mcgirclk clock 25C24 tpmsrc tpm clock source select table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 168 freescale semiconductor, inc.
sim_sopt2 field descriptions (continued) field description selects the clock source for the tpm counter clock 00 clock disabled 01 mcgfllclk clock 10 oscerclk clock 11 mcgirclk clock 23C18 reserved this field is reserved. this read-only field is reserved and always has the value 0. 17C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7C5 clkoutsel clkout select selects the clock to output on the clkout pin. 000 reserved 001 reserved 010 bus clock 011 lpo clock (1 khz) 100 mcgirclk 101 reserved 110 oscerclk 111 reserved 4 rtcclkoutsel rtc clock out select selects either the rtc 1 hz clock or the osc clock to be output on the rtc_clkout pin. 0 rtc 1 hz clock is output on the rtc_clkout pin. 1 oscerclk clock is output on the rtc_clkout pin. 3C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 169
12.2.4 system options register 4 (sim_sopt4) address: 4004_7000h base + 100ch offset = 4004_800ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 0 tpm1clksel tpm0clksel 0 0 0 tpm1ch0src 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 sim_sopt4 field descriptions field description 31C27 reserved this field is reserved. this read-only field is reserved and always has the value 0. 26 reserved this field is reserved. this read-only field is reserved and always has the value 0. 25 tpm1clksel tpm1 external clock pin select selects the external pin used to drive the clock to the tpm1 module. note: the selected pin must also be configured for the tpm external clock function through the appropriate pin control register in the port control module. 0 tpm1 external clock driven by tpm_clkin0 pin. 1 tpm1 external clock driven by tpm_clkin1 pin. 24 tpm0clksel tpm0 external clock pin select selects the external pin used to drive the clock to the tpm0 module. note: the selected pin must also be configured for the tpm external clock function through the appropriate pin control register in the port control module. 0 tpm0 external clock driven by tpm_clkin0 pin. 1 tpm0 external clock driven by tpm_clkin1 pin. 23C21 reserved this field is reserved. this read-only field is reserved and always has the value 0. 20 reserved this field is reserved. this read-only field is reserved and always has the value 0. 19 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 170 freescale semiconductor, inc.
sim_sopt4 field descriptions (continued) field description 18 tpm1ch0src tpm1 channel 0 input capture source select selects the source for tpm1 channel 0 input capture. note: when tpm1 is not in input capture mode, clear this field. 0 tpm1_ch0 signal 1 cmp0 output 17C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 12.2.5 system options register 5 (sim_sopt5) address: 4004_7000h base + 1010h offset = 4004_8010h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 0 0 0 uart0ode w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 0 uart0rxsrc 0 uart0txsrc w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 sim_sopt5 field descriptions field description 31C20 reserved this field is reserved. this read-only field is reserved and always has the value 0. 19 reserved this field is reserved. this read-only field is reserved and always has the value 0. 18 reserved this field is reserved. this read-only field is reserved and always has the value 0. 17 reserved this field is reserved. this read-only field is reserved and always has the value 0. 16 uart0ode uart0 open drain enable 0 open drain is disabled on uart0 1 open drain is enabled on uart0 table continues on the next page... chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 171
sim_sopt5 field descriptions (continued) field description 15C7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 uart0rxsrc uart0 receive data source select selects the source for the uart0 receive data. 0 uart0_rx pin 1 cmp0 output 1 reserved this field is reserved. this read-only field is reserved and always has the value 0. 0 uart0txsrc uart0 transmit data source select selects the source for the uart0 transmit data. 0 uart0_tx pin 1 uart0_tx pin modulated with tpm1 channel 0 output 12.2.6 system options register 7 (sim_sopt7) address: 4004_7000h base + 1018h offset = 4004_8018h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 adc0alttrge n 0 adc0pretrgs el adc0trgsel w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 172 freescale semiconductor, inc.
sim_sopt7 field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 adc0alttrgen adc0 alternate trigger enable enable alternative conversion triggers for adc0. 0 tpm1 channel 0 (a) and channel 1 (b) triggers selected for adc0. 1 alternate trigger selected for adc0. 6C5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4 adc0pretrgsel adc0 pretrigger select selects the adc0 pre-trigger source when alternative triggers are enabled through adc0alttrgen. 0 pre-trigger a 1 pre-trigger b 3C0 adc0trgsel adc0 trigger select selects the adc0 trigger source when alternative triggers are functional in stop and vlps modes. . 0000 external trigger pin input (extrg_in) 0001 cmp0 output 0010 reserved 0011 reserved 0100 pit trigger 0 0101 pit trigger 1 0110 reserved 0111 reserved 1000 tpm0 overflow 1001 tpm1 overflow 1010 reserved 1011 reserved 1100 rtc alarm 1101 rtc seconds 1110 lptmr0 trigger 1111 reserved chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 173
12.2.7 system device identification register (sim_sdid) address: 4004_7000h base + 1024h offset = 4004_8024h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r famid subfamid seriesid sramsize revid dieid 0 pinid w reset * * * * * * * * 0 0 0 1 * * * * * * * * 0 1 0 0 0 0 0 0 * * * * * notes: famid field: device specific value. ? subfamid field: device specific value. ? sramsize field: device specific value. ? revid field: device specific value. ? pinid field: device specific value. ? sim_sdid field descriptions field description 31C28 famid kinetis family id specifies the kinetis family of the device. 0000 kl0x family (low end) 0001 kl1x family (basic) 0010 kl2x family (usb) 0011 kl3x family (segment lcd) 0100 kl4x family (usb and segment lcd) 27C24 subfamid kinetis sub-family id specifies the kinetis sub-family of the device. 0010 klx2 subfamily (low end) 0100 klx4 subfamily (basic analog) 0101 klx5 subfamily (advanced analog) 0110 klx6 subfamily (advanced analog with i2s) 23C20 seriesid kinetis series id specifies the kinetis family of the device. 0001 kl family 19C16 sramsize system sram size specifies the size of the system sram 0000 0.5 kb 0001 1 kb 0010 2 kb 0011 4 kb 0100 8 kb 0101 16 kb table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 174 freescale semiconductor, inc.
sim_sdid field descriptions (continued) field description 0110 32 kb 0111 64 kb 15C12 revid device revision number specifies the silicon implementation number for the device. 11C7 dieid device die number specifies the silicon implementation number for the device. 6C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3C0 pinid pincount identification specifies the pincount of the device. 0000 16-pin 0001 24-pin 0010 32-pin 0011 reserved 0100 48-pin 0101 64-pin 0110 80-pin 0111 reserved 1000 100-pin 1001 reserved 1010 reserved 1011 reserved 1100 reserved 1101 reserved 1110 reserved 1111 reserved chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 175
12.2.8 system clock gating control register 4 (sim_scgc4) address: 4004_7000h base + 1034h offset = 4004_8034h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 1 0 0 spi0 0 cmp 0 0 w reset 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 0 0 uart0 0 0 i2c0 1 0 w reset 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 sim_scgc4 field descriptions field description 31C28 reserved this field is reserved. this read-only field is reserved and always has the value 1. 27C24 reserved this field is reserved. this read-only field is reserved and always has the value 0. 23 reserved this field is reserved. this read-only field is reserved and always has the value 0. 22 spi0 spi0 clock gate control this bit controls the clock gate to the spi0 module. 0 clock disabled 1 clock enabled 21C20 reserved this field is reserved. this read-only field is reserved and always has the value 0. 19 cmp comparator clock gate control this bit controls the clock gate to the comparator module. 0 clock disabled 1 clock enabled 18 reserved this field is reserved. this read-only field is reserved and always has the value 0. 17C14 reserved this field is reserved. this read-only field is reserved and always has the value 0. 13 reserved this field is reserved. this read-only field is reserved and always has the value 0. 12 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 176 freescale semiconductor, inc.
sim_scgc4 field descriptions (continued) field description 11 reserved this field is reserved. this read-only field is reserved and always has the value 0. 10 uart0 uart0 clock gate control this bit controls the clock gate to the uart0 module. 0 clock disabled 1 clock enabled 9C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6 i2c0 i2c0 clock gate control this bit controls the clock gate to the i 2 c0 module. 0 clock disabled 1 clock enabled 5C4 reserved this field is reserved. this read-only field is reserved and always has the value 1. 3C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 12.2.9 system clock gating control register 5 (sim_scgc5) address: 4004_7000h base + 1038h offset = 4004_8038h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 0 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 portb porta 1 0 0 0 0 lptmr w reset 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 sim_scgc5 field descriptions field description 31C20 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 177
sim_scgc5 field descriptions (continued) field description 19 reserved this field is reserved. this read-only field is reserved and always has the value 0. 18C14 reserved this field is reserved. this read-only field is reserved and always has the value 0. 13C11 reserved this field is reserved. this read-only field is reserved and always has the value 0. 10 portb port b clock gate control this bit controls the clock gate to the port b module. 0 clock disabled 1 clock enabled 9 porta port a clock gate control this bit controls the clock gate to the port a module. 0 clock disabled 1 clock enabled 8C7 reserved this field is reserved. this read-only field is reserved and always has the value 1. 6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4C2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 reserved this field is reserved. this read-only field is reserved and always has the value 0. 0 lptmr low power timer access control this bit controls software access to the low power timer module. 0 access disabled 1 access enabled memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 178 freescale semiconductor, inc.
12.2.10 system clock gating control register 6 (sim_scgc6) address: 4004_7000h base + 103ch offset = 4004_803ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 0 rtc 0 adc0 0 tpm1 tpm0 pit 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 dmamux ftf w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 sim_scgc6 field descriptions field description 31 reserved this field is reserved. this read-only field is reserved and always has the value 0. 30 reserved this field is reserved. this read-only field is reserved and always has the value 0. 29 rtc rtc access control this bit controls software access and interrupts to the rtc module. 0 access and interrupts disabled 1 access and interrupts enabled 28 reserved this field is reserved. this read-only field is reserved and always has the value 0. 27 adc0 adc0 clock gate control this bit controls the clock gate to the adc0 module. 0 clock disabled 1 clock enabled 26 reserved this field is reserved. this read-only field is reserved and always has the value 0. 25 tpm1 tpm1 clock gate control this bit controls the clock gate to the tpm1 module. 0 clock disabled 1 clock enabled 24 tpm0 tpm0 clock gate control this bit controls the clock gate to the tpm0 module. table continues on the next page... chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 179
sim_scgc6 field descriptions (continued) field description 0 clock disabled 1 clock enabled 23 pit pit clock gate control this bit controls the clock gate to the pit module. 0 clock disabled 1 clock enabled 22C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15 reserved this field is reserved. this read-only field is reserved and always has the value 0. 14C2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 dmamux dma mux clock gate control this bit controls the clock gate to the dma mux module. 0 clock disabled 1 clock enabled 0 ftf flash memory clock gate control this bit controls the clock gate to the flash memory. flash reads are still supported while the flash memory is clock gated, but entry into low power modes is blocked. 0 clock disabled 1 clock enabled 12.2.11 system clock gating control register 7 (sim_scgc7) address: 4004_7000h base + 1040h offset = 4004_8040h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 dma 0 w reset 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 sim_scgc7 field descriptions field description 31C9 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 180 freescale semiconductor, inc.
sim_scgc7 field descriptions (continued) field description 8 dma dma clock gate control this bit controls the clock gate to the dma module. 0 clock disabled 1 clock enabled 7C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 12.2.12 system clock divider register 1 (sim_clkdiv1) note the clkdiv1 register cannot be written to when the device is in vlpr mode. note reset value loaded during system reset from ftf_fopt[lpboot]. address: 4004_7000h base + 1044h offset = 4004_8044h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r outdiv1 0 outdiv4 0 w reset * * * * 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 * notes: outdiv1 field: the reset value depends on the ftf_fopt[lpboot]. it is loaded with 0000 (divide by one), 0001 (divide by two), 0011 (divide by four), or 0111 (divide by eight). ? sim_clkdiv1 field descriptions field description 31C28 outdiv1 clock 1 output divider value this field sets the divide value for the core/system clock, as well as the bus/flash clocks. at the end of reset, it is loaded with 0000 (divide by one), 0001 (divide by two), 0011 (divide by four), or 0111 (divide by eight) depending on the setting of the two ftf_fopt[lpboot] configuration bits. 0000 divide-by-1. 0001 divide-by-2. 0010 divide-by-3. 0011 divide-by-4. 0100 divide-by-5. 0101 divide-by-6. 0110 divide-by-7. 0111 divide-by-8. table continues on the next page... chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 181
sim_clkdiv1 field descriptions (continued) field description 1000 divide-by-9. 1001 divide-by-10. 1010 divide-by-11. 1011 divide-by-12. 1100 divide-by-13. 1101 divide-by-14. 1110 divide-by-15. 1111 divide-by-16. 27C19 reserved this field is reserved. this read-only field is reserved and always has the value 0. 18C16 outdiv4 clock 4 output divider value this field sets the divide value for the bus and flash clock and is in addition to the system clock divide ratio. at the end of reset, it is loaded with 0001 (divide by two). 000 divide-by-1. 001 divide-by-2. 010 divide-by-3. 011 divide-by-4. 100 divide-by-5. 101 divide-by-6. 110 divide-by-7. 111 divide-by-8. 15C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 182 freescale semiconductor, inc.
12.2.13 flash configuration register 1 (sim_fcfg1) address: 4004_7000h base + 104ch offset = 4004_804ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 pfsize 0 w reset 0 0 0 0 * * * * 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 flashdoze flashdis w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 * notes: pfsize field: device specific value. ? sim_fcfg1 field descriptions field description 31C28 reserved this field is reserved. this read-only field is reserved and always has the value 0. 27C24 pfsize program flash size this field specifies the amount of program flash memory available on the device . undefined values are reserved. 0000 8 kb of program flash memory, 0.25 kb protection region 0001 16 kb of program flash memory, 0.5 kb protection region 0011 32 kb of program flash memory, 1 kb protection region 0101 64 kb of program flash memory, 2 kb protection region 0111 128 kb of program flash memory, 4 kb protection region 1001 256 kb of program flash memory, 8 kb protection region 1111 32 kb of program flash memory, 1 kb protection region table continues on the next page... chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 183
sim_fcfg1 field descriptions (continued) field description 23C2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 flashdoze flash doze when set, flash memory is disabled for the duration of doze mode. this bit should be clear during vlp modes. the flash will be automatically enabled again at the end of doze mode so interrupt vectors do not need to be relocated out of flash memory. the wakeup time from doze mode is extended when this bit is set. an attempt by the dma or other bus master to access the flash when the flash is disabled will result in a bus error. 0 flash remains enabled during doze mode 1 flash is disabled for the duration of doze mode 0 flashdis flash disable flash accesses are disabled (and generate a bus error) and the flash memory is placed in a low power state. this bit should not be changed during vlp modes. relocate the interrupt vectors out of flash memory before disabling the flash. 0 flash is enabled 1 flash is disabled 12.2.14 flash configuration register 2 (sim_fcfg2) address: 4004_7000h base + 1050h offset = 4004_8050h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 maxaddr0 1 0 w reset 0 * * * * * * * 1 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 * notes: maxaddr0 field: device specific value indicating amount of implemented flash. ? sim_fcfg2 field descriptions field description 31 reserved this field is reserved. this read-only field is reserved and always has the value 0. 30C24 maxaddr0 max address block this field concatenated with leading zeros indicates the first invalid address of program flash. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 184 freescale semiconductor, inc.
sim_fcfg2 field descriptions (continued) field description for example, if maxaddr0 = 0x10 the first invalid address of program flash is 0x0002_0000. this would be the maxaddr0 value for a device with 128 kb program flash. 23 reserved this field is reserved. this read-only field is reserved and always has the value 1. 22C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 12.2.15 unique identification register mid-high (sim_uidmh) address: 4004_7000h base + 1058h offset = 4004_8058h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 uid w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 * * * * * * * * * * * * * * * * * notes: uid field: device specific value. ? sim_uidmh field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 uid unique identification unique identification for the device. 12.2.16 unique identification register mid low (sim_uidml) address: 4004_7000h base + 105ch offset = 4004_805ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r uid w reset * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * notes: uid field: device specific value. ? chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 185
sim_uidml field descriptions field description 31C0 uid unique identification unique identification for the device. 12.2.17 unique identification register low (sim_uidl) address: 4004_7000h base + 1060h offset = 4004_8060h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r uid w reset * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * notes: uid field: device specific value. ? sim_uidl field descriptions field description 31C0 uid unique identification unique identification for the device. 12.2.18 cop control register (sim_copc) all of the bits in this register can be written only once after a reset. address: 4004_7000h base + 1100h offset = 4004_8100h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 copt copclks copw w reset 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 186 freescale semiconductor, inc.
sim_copc field descriptions field description 31C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3C2 copt cop watchdog timeout these write-once bits select the timeout period of the cop. the copt field along with the copclks bit define the cop timeout period. 00 cop disabled 01 cop timeout after 2 5 lpo cycles or 2 13 bus clock cycles 10 cop timeout after 2 8 lpo cycles or 2 16 bus clock cycles 11 cop timeout after 2 10 lpo cycles or 2 18 bus clock cycles 1 copclks cop clock select this write-once bit selects the clock source of the cop watchdog. 0 internal 1 khz clock is source to cop 1 bus clock is source to cop 0 copw cop windowed mode windowed mode is only supported when cop is running from the bus clock. the cop window is opened three quarters through the timeout period. 0 normal mode 1 windowed mode 12.2.19 service cop register (sim_srvcop) address: 4004_7000h base + 1104h offset = 4004_8104h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r w reserved srvcop reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 sim_srvcop field descriptions field description 31C8 reserved this field is reserved. 7C0 srvcop sevice cop register write 0x55 and then 0xaa (in that order) to reset the cop timeout counter. chapter 12 system integration module (sim) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 187
12.3 functional description see introduction section. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 188 freescale semiconductor, inc.
chapter 13 system mode controller (smc) 13.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the system mode controller (smc) is responsible for sequencing the system into and out of all low power stop and run modes. specifically, it monitors events to trigger transitions between power modes while controlling the power, clocks, and memories of the system to achieve the power consumption and functionality of that mode. this chapter describes all the available low power modes, the sequence followed to enter/ exit each mode, and the functionality available while in each of the modes. the smc is able to function during even the deepest low power modes. 13.2 modes of operation the arm cpu has three primary modes of operation: ? run ? sleep ? deep sleep the wfi or wfe instruction is used to invoke sleep and deep sleep modes. run, wait and stop are the common terms used for the primary operating modes of freescale microcontrollers. the following table shows the translation between the arm cpu modes and the freescale mcu power modes. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 189
arm cpu mode mcu mode sleep wait deep sleep stop accordingly, the arm cpu documentation refers to sleep and deep sleep, while the freescale mcu documentation normally uses wait and stop. in addition, freescale mcus also augment stop, wait, and run modes in a number of ways. the power management controller (pmc) contains a run and a stop mode regulator. run regulation is used in normal run, wait and stop modes. stop mode regulation is used during all very low power and low leakage modes. during stop mode regulation, the bus frequencies are limited in the very low power modes. the smc provides the user with multiple power options. the very low power run (vlpr) mode can drastically reduce run time power when maximum bus frequency is not required to handle the application needs. from normal run mode, the run mode (runm) field can be modified to change the mcu into vlpr mode when limited frequency is sufficient for the application. from vlpr mode, a corresponding wait (vlpw) and stop (vlps) mode can be entered. depending on the needs of the user application, a variety of stop modes are available that allow the state retention, partial power down or full power down of certain logic and/or memory. i/o states are held in all modes of operation. several registers are used to configure the various modes of operation for the device. the following table describes the power modes available for the device. table 13-1. power modes mode description run the mcu can be run at full speed and the internal supply is fully regulated, that is, in run regulation. this mode is also referred to as normal run mode. wait the core clock is gated off. the system clock continues to operate. bus clocks, if enabled, continue to operate. run regulation is maintained. stop the core clock is gated off. system clocks to other masters and bus clocks are gated off after all stop acknowledge signals from supporting peripherals are valid. vlpr the core, system, bus, and flash clock maximum frequencies are restricted in this mode. see the power management chapter for details about the maximum allowable frequencies. vlpw the core clock is gated off. the system, bus, and flash clocks continue to operate, although their maximum frequency is restricted. see the power management chapter for details on the maximum allowable frequencies. vlps the core clock is gated off. system clocks to other masters and bus clocks are gated off after all stop acknowledge signals from supporting peripherals are valid. lls the core clock is gated off. system clocks to other masters and bus clocks are gated off after all stop acknowledge signals from supporting peripherals are valid. the mcu is placed in a low leakage mode by reducing the voltage to internal logic. internal logic states are retained. table continues on the next page... modes of operation kl04 sub-family reference manual, rev. 3.1, november 2012 190 freescale semiconductor, inc.
table 13-1. power modes (continued) mode description vlls3 the core clock is gated off. system clocks to other masters and bus clocks are gated off after all stop acknowledge signals from supporting peripherals are valid. the mcu is placed in a low leakage mode by powering down the internal logic. all system ram contents are retained and i/o states are held. internal logic states are not retained. vlls1 the core clock is gated off. system clocks to other masters and bus clocks are gated off after all stop acknowledge signals from supporting peripherals are valid. the mcu is placed in a low leakage mode by powering down the internal logic and all system ram. i/o states are held. internal logic states are not retained. vlls0 the core clock is gated off. system clocks to other masters and bus clocks are gated off after all stop acknowledge signals from supporting peripherals are valid. the mcu is placed in a low leakage mode by powering down the internal logic and all system ram. i/o states are held. internal logic states are not retained. the 1khz lpo clock is disabled and the power on reset (por) circuit can be optionally enabled using stopctrl[porpo]. 13.3 memory map and register descriptions details follow about the registers related to the system mode controller. different smc registers reset on different reset types. each register's description provides details. for more information about the types of reset on this chip, refer to the reset section details. note the smc registers can be written only in supervisor mode. write accesses in user mode are blocked and will result in a bus error. smc memory map absolute address (hex) register name width (in bits) access reset value section/ page 4007_e000 power mode protection register (smc_pmprot) 8 r/w 00h 13.3.1/191 4007_e001 power mode control register (smc_pmctrl) 8 r/w 00h 13.3.2/193 4007_e002 stop control register (smc_stopctrl) 8 r/w 03h 13.3.3/194 4007_e003 power mode status register (smc_pmstat) 8 r 01h 13.3.4/195 13.3.1 power mode protection register (smc_pmprot) this register provides protection for entry into any low-power run or stop mode. the enabling of the low-power run or stop mode occurs by configuring the power mode control register (pmctrl). chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 191
the pmprot register can be written only once after any system reset. if the mcu is configured for a disallowed or reserved power mode, the mcu remains in its current power mode. for example, if the mcu is in normal run mode and avlp is 0, an attempt to enter vlpr mode using pmctrl[runm] is blocked and the runm bits remain 00b, indicating the mcu is still in normal run mode. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the reset section details for more information. address: 4007_e000h base + 0h offset = 4007_e000h bit 7 6 5 4 3 2 1 0 read 0 avlp 0 alls 0 avlls 0 write reset 0 0 0 0 0 0 0 0 smc_pmprot field descriptions field description 7C6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5 avlp allow very-low-power modes provided the appropriate control bits are set up in pmctrl, this write-once bit allows the mcu to enter any very-low-power modes: vlpr, vlpw, and vlps. 0 vlpr, vlpw and vlps are not allowed 1 vlpr, vlpw and vlps are allowed 4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 alls allow low-leakage stop mode this write once bit allows the mcu to enter any low-leakage stop mode (lls), provided the appropriate control bits are set up in pmctrl. 0 lls is not allowed 1 lls is allowed 2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 avlls allow very-low-leakage stop mode provided the appropriate control bits are set up in pmctrl, this write once bit allows the mcu to enter any very-low-leakage stop mode (vllsx). 0 any vllsx mode is not allowed 1 any vllsx mode is allowed 0 reserved this field is reserved. this read-only field is reserved and always has the value 0. memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 192 freescale semiconductor, inc.
13.3.2 power mode control register (smc_pmctrl) the pmctrl register controls entry into low-power run and stop modes, provided that the selected power mode is allowed via an appropriate setting of the protection (pmprot) register. note this register is reset on chip por not vlls and by reset types that trigger chip por not vlls. it is unaffected by reset types that do not trigger chip por not vlls. see the reset section details for more information. address: 4007_e000h base + 1h offset = 4007_e001h bit 7 6 5 4 3 2 1 0 read 0 runm 0 stopa stopm write reset 0 0 0 0 0 0 0 0 smc_pmctrl field descriptions field description 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6C5 runm run mode control when written, causes entry into the selected run mode. writes to this field are blocked if the protection level has not been enabled using the pmprot register. this field is cleared by hardware on any exit to normal run mode. note: runm must be set to vlpr only when pmstat=run. after being written to vlpr, runm should not be written back to run until pmstat=vlpr. note: runm must be set to run only when pmstat=vlpr. after being written to run, runm should not be written back to vlpr until pmstat=run. 00 normal run mode (run) 01 reserved 10 very-low-power run mode (vlpr) 11 reserved 4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 stopa stop aborted when set, this read-only status bit indicates an interrupt or reset occured during the previous stop mode entry sequence, preventing the system from entering that mode. this bit is cleared by hardware at the beginning of any stop mode entry sequence and is set if the sequence was aborted. 0 the previous stop mode entry was successsful. 1 the previous stop mode entry was aborted. table continues on the next page... chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 193
smc_pmctrl field descriptions (continued) field description 2C0 stopm stop mode control when written, controls entry into the selected stop mode when sleep-now or sleep-on-exit mode is entered with sleepdeep=1 . writes to this field are blocked if the protection level has not been enabled using the pmprot register. after any system reset, this field is cleared by hardware on any successful write to the pmprot register. note: when set to vllsx, the vllsm bits in the stopctrl register is used to further select the particular vlls submode which will be entered. note: when set to stop, the pstopo bits in the stopctrl register can be used to select a partial stop mode if desired. 000 normal stop (stop) 001 reserved 010 very-low-power stop (vlps) 011 low-leakage stop (lls) 100 very-low-leakage stop (vllsx) 101 reserved 110 reseved 111 reserved 13.3.3 stop control register (smc_stopctrl) the stopctrl register provides various control bits allowing the user to fine tune power consumption during the stop mode selected by the stopm field. note this register is reset on chip por not vlls and by reset types that trigger chip por not vlls. it is unaffected by reset types that do not trigger chip por not vlls. see the reset section details for more information. address: 4007_e000h base + 2h offset = 4007_e002h bit 7 6 5 4 3 2 1 0 read pstopo porpo 0 0 vllsm write reset 0 0 0 0 0 0 1 1 smc_stopctrl field descriptions field description 7C6 pstopo partial stop option these bits control whether a partial stop mode is entered when stopm=stop. when entering a partial stop mode from run mode, the pmc, mcg and flash remain fully powered, allowing the device to wakeup almost instantaneously at the expense of higher power consumption. in pstop2, only system table continues on the next page... memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 194 freescale semiconductor, inc.
smc_stopctrl field descriptions (continued) field description clocks are gated allowing peripherals running on bus clock to remain fully functional. in pstop1, both system and bus clocks are gated. 00 stop - normal stop mode 01 pstop1 - partial stop with both system and bus clocks disabled 10 pstop2 - partial stop with system clock disabled and bus clock enabled 11 reserved 5 porpo por power option this bit controls whether the por detect circuit is enabled in vlls0 mode. 0 por detect circuit is enabled in vlls0 1 por detect circuit is disabled in vlls0 4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2C0 vllsm vlls mode control. this field controls which vlls sub-mode to enter if stopm=vlls. 000 vlls0 001 vlls1 010 reserved 011 vlls3 100 reserved 101 reserved 110 reserved 111 reserved 13.3.4 power mode status register (smc_pmstat) pmstat is a read-only, one-hot register which indicates the current power mode of the system. note this register is reset on chip por not vlls and by reset types that trigger chip por not vlls. it is unaffected by reset types that do not trigger chip por not vlls. see the reset section details for more information. chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 195
address: 4007_e000h base + 3h offset = 4007_e003h bit 7 6 5 4 3 2 1 0 read 0 pmstat write reset 0 0 0 0 0 0 0 1 smc_pmstat field descriptions field description 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6C0 pmstat note: when debug is enabled, the pmstat will not update to stop or vlps note: when a pstop mode is enabled, the pmstat will not update to stop or vlps 000_0001 current power mode is run 000_0010 current power mode is stop 000_0100 current power mode is vlpr 000_1000 current power mode is vlpw 001_0000 current power mode is vlps 010_0000 current power mode is lls 100_0000 current power mode is vlls 13.4 functional description 13.4.1 power mode transitions the following figure shows the power mode state transitions available on the chip. any reset always brings the mcu back to the normal run state. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 196 freescale semiconductor, inc.
wait stop run lls vlls 3, 1, 0 vlps vlpr vlpw any reset 4 6 7 3 1 2 8 10 11 9 5 figure 13-5. power mode state diagram the following table defines triggers for the various state transitions shown in the previous figure. table 13-7. power mode transition triggers transition # from to trigger conditions 1 run wait sleep-now or sleep-on-exit modes entered with sleepdeep clear, controlled in system control register in arm core. see note. 1 wait run interrupt or reset table continues on the next page... chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 197
table 13-7. power mode transition triggers (continued) transition # from to trigger conditions 2 run stop pmctrl[runm]=00, pmctrl[stopm]=000 2 sleep-now or sleep-on-exit modes entered with sleepdeep set, which is controlled in system control register in arm core. see note. 1 stop run interrupt or reset 3 run vlpr the core, system, bus and flash clock frequencies are restricted in this mode. see the power management chapter for the maximum allowable frequencies. set pmprot[avlp]=1, pmctrl[runm]=10. vlpr run set pmctrl[runm]=00 or reset. 4 vlpr vlpw sleep-now or sleep-on-exit modes entered with sleepdeep clear, which is controlled in system control register in arm core. see note. 1 vlpw vlpr interrupt 5 vlpw run reset 6 vlpr vlps pmctrl[stopm]=000 3 or 010, sleep-now or sleep-on-exit modes entered with sleepdeep set, which is controlled in system control register in arm core. see note. 1 vlps vlpr interrupt note: if vlps was entered directly from run, hardware will not allow this transition and will force exit back to run 7 run vlps pmprot[avlp]=1, pmctrl[stopm]=010, sleep-now or sleep-on-exit modes entered with sleepdeep set, which is controlled in system control register in arm core. see note. 1 vlps run interrupt and vlps mode was entered directly from run or reset 8 run vllsx pmprot[avlls]=1, pmctrl[stopm]=100, stopctrl[vllsm]=x (vllsx), sleep-now or sleep-on-exit modes entered with sleepdeep set, which is controlled in system control register in arm core. vllsx run wakeup from enabled llwu input source or reset pin 9 vlpr vllsx pmprot[avlls]=1, pmctrl[stopm]=100, stopctrl[vllsm]=x (vllsx), sleep-now or sleep-on-exit modes entered with sleepdeep set, which is controlled in system control register in arm core. table continues on the next page... functional description kl04 sub-family reference manual, rev. 3.1, november 2012 198 freescale semiconductor, inc.
table 13-7. power mode transition triggers (continued) transition # from to trigger conditions 10 run lls pmprot[alls]=1, pmctrl[stopm]=011, sleep-now or sleep-on-exit modes entered with sleepdeep set, which is controlled in system control register in arm core. lls run wakeup from enabled llwu input source or reset pin. 11 vlpr lls pmprot[alls]=1, pmctrl[stopm]=011, sleep-now or sleep-on-exit modes entered with sleepdeep set, which is controlled in system control register in arm core. 1. if debug is enabled, the core clock remains to support debug. 2. if pmctrl[stopm]=000 and stopctrl[pstopo]=01 or 10, then only a partial stop mode is entered instead of stop 3. if pmctrl[stopm]=000 and stopctrl[pstopo]=00, then vlps mode is entered instead of stop. if pmctrl[stopm]=000 and stopctrl[pstopo]=01 or 10, then only a partial stop mode is entered instead of vlps 13.4.2 power mode entry/exit sequencing when entering or exiting low-power modes, the system must conform to an orderly sequence to manage transitions safely. the smc manages the system's entry into and exit from all power modes. the following diagram illustrates the connections of the smc with other system components in the chip that are necessary to sequence the system through all power modes. chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 199
system mode controller (smc) system power (pmc) low - leakage wakeup (llwu) system clocks (mcg) lp exit flash cpu lp exit clock control module (ccm) module memory bus masters low power bus (non-cpu) bus slaves low power bus stop/wait ccm low power bus mcg enable pmc low power bus flash low power bus reset control (rcm) module figure 13-6. low-power system components and connections 13.4.2.1 stop mode entry sequence entry into a low-power stop mode (stop, vlps, lls, vllsx) is initiated by cpu execution of the wfi instruction. after the instruction is executed, the following sequence occurs: 1. the cpu clock is gated off immediately. 2. requests are made to all non-cpu bus masters to enter stop mode. 3. after all masters have acknowledged they are ready to enter stop mode, requests are made to all bus slaves to enter stop mode. 4. after all slaves have acknowledged they are ready to enter stop mode, all system and bus clocks are gated off. 5. clock generators are disabled in the mcg. 6. the on-chip regulator in the pmc and internal power switches are configured to meet the power consumption goals for the targeted low-power mode. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 200 freescale semiconductor, inc.
13.4.2.2 stop mode exit sequence exit from a low-power stop mode is initiated either by a reset or an interrupt event. the following sequence then executes to restore the system to a run mode (run or vlpr): 1. the on-chip regulator in the pmc and internal power switches are restored. 2. clock generators are enabled in the mcg. 3. system and bus clocks are enabled to all masters and slaves. 4. the cpu clock is enabled and the cpu begins servicing the reset or interrupt that initiated the exit from the low-power stop mode. 13.4.2.3 aborted stop mode entry if an interrupt or a reset occurs during a stop entry sequence, the smc can abort the transition early and return to run mode without completely entering the stop mode. an aborted entry is possible only if the reset or interrupt occurs before the pmc begins the transition to stop mode regulation. after this point, the interrupt or reset is ignored until the pmc has completed its transition to stop mode regulation. when an aborted stop mode entry sequence occurs, the smc's pmctrl[stopa] is set to 1. 13.4.2.4 transition to wait modes for wait modes (wait and vlpw), the cpu clock is gated off while all other clocking continues, as in run and vlpr mode operation. some modules that support stop-in- wait functionality have their clocks disabled in these configurations. 13.4.2.5 transition from stop modes to debug mode the debugger module supports a transition from stop, wait, vlps, and vlpw back to a halted state when the debugger has been enabled, that is, enbdm is 1. as part of this transition, system clocking is re-established and is equivalent to the normal run and vlpr mode clocking configuration. 13.4.3 run modes the device contains two different run modes: ? run ? very low-power run (vlpr) chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 201
13.4.3.1 run mode this is the normal operating mode for the device. this mode is selected after any reset. when the arm processor exits reset, it sets up the stack, program counter (pc), and link register (lr): ? the processor reads the start sp (sp_main) from vector-table offset 0x000 ? the processor reads the start pc from vector-table offset 0x004 ? lr is set to 0xffff_ffff. to reduce power in this mode, disable the clocks to unused modules using their corresponding clock gating control bits in the sim's registers. 13.4.3.2 very-low power run (vlpr) mode in vlpr mode, the on-chip voltage regulator is put into a stop mode regulation state. in this state, the regulator is designed to supply enough current to the mcu over a reduced frequency. to further reduce power in this mode, disable the clocks to unused modules using their corresponding clock gating control bits in the sim's registers. before entering this mode, the following conditions must be met: ? the mcg must be configured in a mode which is supported during vlpr. see the power management details for information about these mcg modes. ? all clock monitors in the mcg must be disabled. ? the maximum frequencies of the system, bus, flash, and core are restricted. see the power management details about which frequencies are supported. ? mode protection must be set to allow vlp modes, that is, pmprot[avlp] is 1. ? pmctrl[runm] is set to 10b to enter vlpr. ? flash programming/erasing is not allowed. note do not change the clock frequency while in vlpr mode, because the regulator is slow responding and cannot manage fast load transitions. in addition, do not modify the clock source in the mcg module, the module clock enables in the sim, or any clock divider registers. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 202 freescale semiconductor, inc.
to reenter normal run mode, clear runm. the pmstat register is a read-only status register that can be used to determine when the system has completed an exit to run mode. when pmstat=run, the system is in run regulation and the mcu can run at full speed in any clock mode. if a higher execution frequency is desired, poll the pmstat register until it is set to run when returning from vlpr mode. any reset always causes an exit from vlpr and returns the device to run mode after the mcu exits its reset flow. 13.4.4 wait modes this device contains two different wait modes: ? wait ? very-low power wait (vlpw) 13.4.4.1 wait mode wait mode is entered when the arm core enters the sleep-now or sleep-on-exit modes while sleedeep is cleared. the arm cpu enters a low-power state in which it is not clocked, but peripherals continue to be clocked provided they are enabled. clock gating to the peripheral is enabled via the sim.. when an interrupt request occurs, the cpu exits wait mode and resumes processing in run mode, beginning with the stacking operations leading to the interrupt service routine. a system reset will cause an exit from wait mode, returning the device to normal run mode. 13.4.4.2 very-low-power wait (vlpw) mode vlpw is entered by the entering the sleep-now or sleep-on-exit mode while sleepdeep is cleared and the mcu is in vlpr mode. in vlpw, the on-chip voltage regulator remains in its stop regulation state. in this state, the regulator is designed to supply enough current to the mcu over a reduced frequency. to further reduce power in this mode, disable the clocks to unused modules by clearing the peripherals' corresponding clock gating control bits in the sim. vlpr mode restrictions also apply to vlpw. chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 203
when an interrupt from vlpw occurs, the device returns to vlpr mode to execute the interrupt service routine. a system reset will cause an exit from vlpw mode, returning the device to normal run mode. 13.4.5 stop modes this device contains a variety of stop modes to meet your application needs. the stop modes range from: ? a stopped cpu, with all i/o, logic, and memory states retained, and certain asynchronous mode peripherals operating to: ? a powered down cpu, with only i/o and a small register file retained, very few asynchronous mode peripherals operating, while the remainder of the mcu is powered down. the choice of stop mode depends upon the user's application, and how power usage and state retention versus functional needs may be traded off. note all clock monitors must be disabled before entering these low- power modes: stop, vlps, vlpr, vlpw, lls, and vllsx. the various stop modes are selected by setting the appropriate fields in pmprot and pmctrl. the selected stop mode mode is entered during the sleep-now or sleep-on-exit entry with the sleepdeep bit set in the system control register in the arm core. the available stop modes are: ? normal stop (stop) ? very-low power stop (vlps) ? low-leakage stop (lls) ? very-low-leakage stop (vllsx) 13.4.5.1 stop mode stop mode is entered via the sleep-now or sleep-on-exit with the sleepdeep bit set in the system control register in the arm core. the mcg module can be configured to leave the reference clocks running. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 204 freescale semiconductor, inc.
a module capable of providing an asynchronous interrupt to the device takes the device out of stop mode and returns the device to normal run mode. refer to the device's power management chapter for peripheral, i/o, and memory operation in stop mode. when an interrupt request occurs, the cpu exits stop mode and resumes processing, beginning with the stacking operations leading to the interrupt service routine. a system reset will cause an exit from stop mode, returning the device to normal run mode via an mcu reset. 13.4.5.2 very-low-power stop (vlps) mode vlps mode can be entered in one of two ways: ? entry into stop via the sleep-now or sleep-on-exit with the sleepdeep bit set in the system control register in the arm core while the mcu is in vlpr mode and stopm=010 or 000 in the pmctrl register. ? entry into stop via the sleep-now or sleep-on-exit with the sleepdeep bit set in the system control register in the arm core while the mcu is in normal run mode and stopm=010 in the pmctrl register. when vlps is entered directly from run mode, exit to vlpr is disabled by hardware and the system will always exit back to run. in vlps, the on-chip voltage regulator remains in its stop regulation state as in vlpr. a module capable of providing an asynchronous interrupt to the device takes the device out of vlps and returns the device to vlpr mode. a system reset will also cause a vlps exit, returning the device to normal run mode. 13.4.5.3 low-leakage stop (lls) mode low-leakage stop (lls) mode can be entered from normal run or vlpr modes. the mcu enters lls mode if: ? in sleep-now or sleep-on-exit mode, sleepdeep is set in the system control register in the arm core, and ? the device is configured as shown in table 13-7 . in lls, the on-chip voltage regulator is in stop regulation. most of the peripherals are put in a state-retention mode that does not allow them to operate while in lls. chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 205
before entering lls mode, the user should configure the low-leakage wakeup (llwu) module to enable the desired wakeup sources. the available wakeup sources in lls are detailed in the chip configuration details for this device. after wakeup from lls, the device returns to normal run mode with a pending llwu module interrupt. in the llwu interrupt service routine (isr), the user can poll the llwu module wakeup flags to determine the source of the wakeup. note the llwu interrupt must not be masked by the interrupt controller to avoid a scenario where the system does not fully exit stop mode on an lls recovery. an asserted reset pin will cause an exit from lls mode, returning the device to normal run mode. when lls is exiting via the reset pin, the pin and wakeup bits are set in the srs0 register of the reset control module (rcm). 13.4.5.4 very-low-leakage stop (vllsx) modes this device contains these very low leakage modes: ? vlls3 ? vlls1 ? vlls0 vllsx is often used in this document to refer to all of these modes. all vllsx modes can be entered from normal run or vlpr modes. the mcu enters the configured vlls mode if: ? in sleep-now or sleep-on-exit mode, the sleepdeep bit is set in the system control register in the arm core, and ? the device is configured as shown in table 13-7 . in vlls, the on-chip voltage regulator is in its stop-regulation state while most digital logic is powered off. before entering vlls mode, the user should configure the low-leakage wakeup (llwu) module to enable the desired wakeup sources. the available wakeup sources in vlls are detailed in the chip configuration details for this device. after wakeup from vlls, the device returns to normal run mode with a pending llwu interrupt. in the llwu interrupt service routine (isr), the user can poll the llwu module wakeup flags to determine the source of the wakeup. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 206 freescale semiconductor, inc.
when entering vlls, each i/o pin is latched as configured before executing vlls. because all digital logic in the mcu is powered off, all port and peripheral data is lost during vlls. this information must be restored before the ackiso bit in the pmc is set. an asserted reset pin will cause an exit from any vlls mode, returning the device to normal run mode. when exiting vlls via the reset pin, the pin and wakeup bits are set in the srs0 register of the reset control module (rcm). 13.4.6 debug in low power modes when the mcu is secure, the device disables/limits debugger operation. when the mcu is unsecure, the arm debugger can assert two power-up request signals: ? system power up, via syspwr in the debug port control/stat register ? debug power up, via cdbgpwrupreq in the debug port control/stat register when asserted while in run, wait, vlpr, or vlpw, the mode controller drives a corresponding acknowledge for each signal, that is, both cdbgpwrupack and csyspwrupack. when both requests are asserted, the mode controller handles attempts to enter stop and vlps by entering an emulated stop state. in this emulated stop state: ? the regulator is in run regulation, ? the mcg-generated clock source is enabled, ? all system clocks, except the core clock, are disabled, ? the debug module has access to core registers, and ? access to the on-chip peripherals is blocked. no debug is available while the mcu is in lls or vlls modes. lls is a state-retention mode and all debug operation can continue after waking from lls, even in cases where system wakeup is due to a system reset event. entering into a vlls mode causes all of the debug controls and settings to be powered off. to give time to the debugger to sync with the mcu, the mdm ap control register includes a very-low-leakage debug request (vlldbgreq) bit that is set to configure the reset controller logic to hold the system in reset after the next recovery from a vlls mode. this bit allows the debugger time to reinitialize the debug module before the debug session continues. chapter 13 system mode controller (smc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 207
the mdm ap control register also includes a very low leakage debug acknowledge (vlldbgack) bit that is set to release the arm core being held in reset following a vlls recovery. the debugger reinitializes all debug ip, and then asserts the vlldbgack control bit to allow the rcm to release the arm core from reset and allow cpu operation to begin. the vlldbgack bit is cleared by the debugger (or can be left set as is) or clears automatically due to the reset generated as part of the next vlls recovery. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 208 freescale semiconductor, inc.
chapter 14 power management controller (pmc) 14.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the power management controller (pmc) contains the internal voltage regulator, power on reset (por), and low voltage detect system. 14.2 features the pmc features include: ? internal voltage regulator ? active por providing brown-out detect ? low-voltage detect supporting two low-voltage trip points with four warning levels per trip point 14.3 low-voltage detect (lvd) system this device includes a system to guard against low-voltage conditions. this protects memory contents and controls mcu system states during supply voltage variations. the system is comprised of a power-on reset (por) circuit and a lvd circuit with a user- selectable trip voltage: high (v lvdh ) or low (v lvdl ). the trip voltage is selected by the lvdsc1[lvdv] bits. the lvd is disabled upon entering vlpx, lls, and vllsx modes. two flags are available to indicate the status of the low-voltage detect system: kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 209
? the low voltage detect flag (lvdf) operates in a level sensitive manner. the lvdf bit is set when the supply voltage falls below the selected trip point (vlvd). the lvdf bit is cleared by writing one to the lvdack bit, but only if the internal supply has returned above the trip point; otherwise, the lvdf bit remains set. ? the low voltage warning flag (lvwf) operates in a level sensitive manner. the lvwf bit is set when the supply voltage falls below the selected monitor trip point (vlvw). the lvwf bit is cleared by writing one to the lvwack bit, but only if the internal supply has returned above the trip point; otherwise, the lvwf bit remains set. 14.3.1 lvd reset operation by setting the lvdre bit, the lvd generates a reset upon detection of a low voltage condition. the low voltage detection threshold is determined by the lvdv bits. after an lvd reset occurs, the lvd system holds the mcu in reset until the supply voltage rises above this threshold. the lvd bit in the srs register is set following an lvd or power- on reset. 14.3.2 lvd interrupt operation by configuring the lvd circuit for interrupt operation (lvdie set and lvdre clear), lvdsc1[lvdf] is set and an lvd interrupt request occurs upon detection of a low voltage condition. the lvdf bit is cleared by writing one to the lvdsc1[lvdack] bit. 14.3.3 low-voltage warning (lvw) interrupt operation the lvd system contains a low-voltage warning flag (lvwf) to indicate that the supply voltage is approaching, but is above, the lvd voltage. the lvw also has an interrupt, which is enabled by setting the lvdsc2[lvwie] bit. if enabled, an lvw interrupt request occurs when the lvwf is set. lvwf is cleared by writing one to the lvdsc2[lvwack] bit. the lvdsc2[lvwv] bits select one of four trip voltages: ? highest: v lvw4 ? two mid-levels: v lvw3 and v lvw2 ? lowest: v lvw1 low-voltage detect (lvd) system kl04 sub-family reference manual, rev. 3.1, november 2012 210 freescale semiconductor, inc.
14.4 i/o retention when in lls mode, the i/o pins are held in their input or output state. upon wakeup, the pmc is re-enabled, goes through a power up sequence to full regulation, and releases the logic from state retention mode. the i/o are released immediately after a wakeup or reset event. in the case of lls exit via a reset pin, the i/o default to their reset state. when in vlls modes, the i/o states are held on a wakeup event (with the exception of wakeup by reset event) until the wakeup has been acknowledged via a write to the ackiso bit. in the case of vlls exit via a reset pin, the i/o are released and default to their reset state. in this case, no write to the ackiso is needed. 14.5 memory map and register descriptions pmc register details follow. note different portions of pmc registers are reset only by particular reset types. each register's description provides details. for more information about the types of reset on this chip, refer to the reset section details. the pmc registers can be written only in supervisor mode. write accesses in user mode are blocked and will result in a bus error. pmc memory map absolute address (hex) register name width (in bits) access reset value section/ page 4007_d000 low voltage detect status and control 1 register (pmc_lvdsc1) 8 r/w 10h 14.5.1/212 4007_d001 low voltage detect status and control 2 register (pmc_lvdsc2) 8 r/w 00h 14.5.2/213 4007_d002 regulator status and control register (pmc_regsc) 8 r/w 04h 14.5.3/214 chapter 14 power management controller (pmc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 211
14.5.1 low voltage detect status and control 1 register (pmc_lvdsc1) this register contains status and control bits to support the low voltage detect function. this register should be written during the reset initialization program to set the desired controls even if the desired settings are the same as the reset settings. while the device is in the very low power or low leakage modes, the lvd system is disabled regardless of lvdsc1 settings. to protect systems that must have lvd always on, configure the smc's power mode protection register (pmprot) to disallow any very low power or low leakage modes from being enabled. see the device's data sheet for the exact lvd trip voltages. note the lvdv bits are reset solely on a por only event. the register's other bits are reset on chip reset not vlls. for more information about these reset types, refer to the reset section details. address: 4007_d000h base + 0h offset = 4007_d000h bit 7 6 5 4 3 2 1 0 read lvdf 0 lvdie lvdre 0 lvdv write lvdack reset 0 0 0 1 0 0 0 0 pmc_lvdsc1 field descriptions field description 7 lvdf low-voltage detect flag this read-only status bit indicates a low-voltage detect event. 0 low-voltage event not detected 1 low-voltage event detected 6 lvdack low-voltage detect acknowledge this write-only bit is used to acknowledge low voltage detection errors. write 1 to clear lvdf. reads always return 0. 5 lvdie low-voltage detect interrupt enable enables hardware interrupt requests for lvdf. 0 hardware interrupt disabled (use polling) 1 request a hardware interrupt when lvdf = 1 table continues on the next page... memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 212 freescale semiconductor, inc.
pmc_lvdsc1 field descriptions (continued) field description 4 lvdre low-voltage detect reset enable this write-once bit enables lvdf events to generate a hardware reset. additional writes are ignored. 0 lvdf does not generate hardware resets 1 force an mcu reset when lvdf = 1 3C2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1C0 lvdv low-voltage detect voltage select selects the lvd trip point voltage (v lvd ). 00 low trip point selected (v lvd = v lvdl ) 01 high trip point selected (v lvd = v lvdh ) 10 reserved 11 reserved 14.5.2 low voltage detect status and control 2 register (pmc_lvdsc2) this register contains status and control bits to support the low voltage warning function. while the device is in the very low power or low leakage modes, the lvd system is disabled regardless of lvdsc2 settings. see the device's data sheet for the exact lvd trip voltages. note the lvw trip voltages depend on lvwv and lvdv bits. note the lvwv bits are reset solely on a por only event. the register's other bits are reset on chip reset not vlls. for more information about these reset types, refer to the reset section details. address: 4007_d000h base + 1h offset = 4007_d001h bit 7 6 5 4 3 2 1 0 read lvwf 0 lvwie 0 lvwv write lvwack reset 0 0 0 0 0 0 0 0 chapter 14 power management controller (pmc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 213
pmc_lvdsc2 field descriptions field description 7 lvwf low-voltage warning flag this read-only status bit indicates a low-voltage warning event. lvwf is set when v supply transitions below the trip point, or after reset and v supply is already below v lvw . lvwf bit may be 1 after power on reset, therefore, to use lvw interrupt function, before enabling lvwie, lvwf must be cleared by writing lvwack first. 0 low-voltage warning event not detected 1 low-voltage warning event detected 6 lvwack low-voltage warning acknowledge this write-only bit is used to acknowledge low voltage warning errors. write 1 to clear lvwf. reads always return 0. 5 lvwie low-voltage warning interrupt enable enables hardware interrupt requests for lvwf. 0 hardware interrupt disabled (use polling) 1 request a hardware interrupt when lvwf = 1 4C2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1C0 lvwv low-voltage warning voltage select selects the lvw trip point voltage (v lvw ). the actual voltage for the warning depends on lvdsc1[lvdv]. 00 low trip point selected (v lvw = v lvw1 ) 01 mid 1 trip point selected (v lvw = v lvw2 ) 10 mid 2 trip point selected (v lvw = v lvw3 ) 11 high trip point selected (v lvw = v lvw4 ) 14.5.3 regulator status and control register (pmc_regsc) the pmc contains an internal voltage regulator. the voltage regulator design uses a bandgap reference that is also available through a buffer as input to certain internal peripherals, such as the cmp and adc. the internal regulator provides a status bit (regons) indicating the regulator is in run regulation. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. see the reset section for more information. memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 214 freescale semiconductor, inc.
address: 4007_d000h base + 2h offset = 4007_d002h bit 7 6 5 4 3 2 1 0 read 0 reserved bgen ackiso regons reserved bgbe write w1c reset 0 0 0 0 0 1 0 0 pmc_regsc field descriptions field description 7C6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5 reserved this field is reserved. 4 bgen bandgap enable in vlpx operation bgen controls whether the bandgap is enabled in lower power modes of operation (vlpx, lls, and vllsx). when on-chip peripherals require the bandgap voltage reference in low power modes of operation, set bgen to continue to enable the bandgap operation. note: when the bandgap voltage reference is not needed in low power modes, clear bgen to avoid excess power consumption. 0 bandgap voltage reference is disabled in vlpx , lls , and vllsx modes 1 bandgap voltage reference is enabled in vlpx , lls , and vllsx modes 3 ackiso acknowledge isolation reading this bit indicates whether certain peripherals and the i/o pads are in a latched state as a result of having been in a vlls mode. writing one to this bit when it is set releases the i/o pads and certain peripherals to their normal run mode state. note: after recovering from a vlls mode, user should restore chip configuration before clearing ackiso. in particular, pin configuration for enabled llwu wakeup pins should be restored to avoid any llwu flag from being falsely set when ackiso is cleared. 0 peripherals and i/o pads are in normal run state 1 certain peripherals and i/o pads are in an isolated and latched state 2 regons regulator in run regulation status this read-only bit provides the current status of the internal voltage regulator. 0 regulator is in stop regulation or in transition to/from it 1 regulator is in run regulation 1 reserved this field is reserved. note: this reserved bit must remain cleared (set to 0). 0 bgbe bandgap buffer enable enables the bandgap buffer. 0 bandgap buffer not enabled 1 bandgap buffer enabled chapter 14 power management controller (pmc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 215
memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 216 freescale semiconductor, inc.
chapter 15 low-leakage wakeup unit (llwu) 15.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the llwu module allows the user to select up to 16 external pin sources and up to 8 internal modules as a wakeup source from low-leakage power modes. the input sources are described in the device's chip configuration details. each of the available wakeup sources can be individually enabled. the llwu module also includes two optional digital pin filters for the external wakeup pins. 15.1.1 features the llwu module features include: ? support for up to 16 external input pins and up to 8 internal modules with individual enable bits ? input sources may be external pins or from internal peripherals capable of running in lls or vlls. see the chip configuration information for wakeup input sources for this device. ? external pin wakeup inputs, each of which is programmable as falling-edge, rising- edge, or any change ? wakeup inputs that are activated if enabled after mcu enters a low-leakage power mode ? optional digital filters provided to qualify an external pin detect. when entering vlls0, the filters are disabled and bypassed. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 217
15.1.2 modes of operation the llwu module becomes functional on entry into a low-leakage power mode. after recovery from lls, the llwu is immediately disabled. after recovery from vlls, the llwu continues to detect wakeup events until the user has acknowledged the wakeup via a write to the pmc_regsc[ackiso] bit. 15.1.2.1 lls mode the llwu module provides up to 16 external wakeup inputs and up to 8 internal module wakeup inputs. wakeup events due to external wakeup inputs and internal module wakeup inputs result in an interrupt flow when exiting lls. note the llwu interrupt must not be masked by the interrupt controller to avoid a scenario where the system does not fully exit stop mode on an lls recovery. 15.1.2.2 vlls modes the llwu module provides up to 16 external wakeup inputs and up to 8 internal module wakeup inputs. all wakeup events result in vlls exit via a reset flow. 15.1.2.3 non-low leakage modes the llwu is not active in all non-low leakage modes where detection and control logic are in a static state. the llwu registers are accessible in non-low leakage modes and are available for configuring and reading status when bus transactions are possible. when the wakeup pin filters are enabled, filter operation begins immediately. if a low leakage mode is entered within 5 lpo clock cycles of an active edge, the edge event will be detected by the llwu. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 218 freescale semiconductor, inc.
15.1.2.4 debug mode when the chip is in debug mode and then enters lls or a vllsx mode, no debug logic works in the fully-functional low-leakage mode. upon an exit from the lls or vllsx mode, the llwu becomes inactive. 15.1.3 block diagram the following figure is the block diagram for the llwu module. module0 interrupt flag (llwu_m0if) wume0 llwu_mwuf0 occurred internal module sources llwu controller external pin sources exit low leakge mode interrupt flow reset flow llwu_p0 llwu_p15 pin filter 1 wakeup occurred interrupt module flag detect wupe15 2 edge detect enter low leakge mode wupe0 edge detect module7 interrupt flag (llwu_m7if) wume7 llwu_mwuf7 occurred interrupt module flag detect lpo pin filter 2 lpo filt1[filte] pin filter 1 synchronizer synchronizer edge detect llwu_p15 wakeup occurred edge detect pin filter 2 wakeup occurred 2 llwu_p0 wakeup occurred filt2[filtsel] filt1[filtsel] filt2[filte] figure 15-1. llwu block diagram chapter 15 low-leakage wakeup unit (llwu) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 219
15.2 llwu signal descriptions the signal properties of llwu are shown in the following table. the external wakeup input pins can be enabled to detect either rising-edge, falling-edge, or on any change. table 15-1. llwu signal descriptions signal description i/o llwu_pn wakeup inputs (n = 0-15) i 15.3 memory map/register definition the llwu includes the following registers: ? five 8-bit wakeup source enable registers ? enable external pin input sources ? enable internal peripheral sources ? three 8-bit wakeup flag registers ? indication of wakeup source that caused exit from a low-leakage power mode includes external pin or internal module interrupt ? two 8-bit wakeup pin filter enable registers note the llwu registers can be written only in supervisor mode. write accesses in user mode are blocked and will result in a bus error. all llwu registers are reset by chip reset not vlls and by reset types that trigger chip reset not vlls. each register's displayed reset value represents this subset of reset types. llwu registers are unaffected by reset types that do not trigger chip reset not vlls. for more information about the types of reset on this chip, refer to the introduction details. llwu signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 220 freescale semiconductor, inc.
llwu memory map absolute address (hex) register name width (in bits) access reset value section/ page 4007_c000 llwu pin enable 1 register (llwu_pe1) 8 r/w 00h 15.3.1/221 4007_c001 llwu pin enable 2 register (llwu_pe2) 8 r/w 00h 15.3.2/222 4007_c002 llwu module enable register (llwu_me) 8 r/w 00h 15.3.3/223 4007_c003 llwu flag 1 register (llwu_f1) 8 r/w 00h 15.3.4/225 4007_c004 llwu flag 3 register (llwu_f3) 8 r 00h 15.3.5/226 4007_c005 llwu pin filter 1 register (llwu_filt1) 8 r/w 00h 15.3.6/228 4007_c006 llwu pin filter 2 register (llwu_filt2) 8 r/w 00h 15.3.7/229 15.3.1 llwu pin enable 1 register (llwu_pe1) llwu_pe1 contains the field to enable and select the edge detect type for the external wakeup input pins llwu_p3-llwu_p0. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the introduction details for more information. address: 4007_c000h base + 0h offset = 4007_c000h bit 7 6 5 4 3 2 1 0 read wupe3 wupe2 wupe1 wupe0 write reset 0 0 0 0 0 0 0 0 llwu_pe1 field descriptions field description 7C6 wupe3 wakeup pin enable for llwu_p3 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 5C4 wupe2 wakeup pin enable for llwu_p2 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection table continues on the next page... chapter 15 low-leakage wakeup unit (llwu) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 221
llwu_pe1 field descriptions (continued) field description 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 3C2 wupe1 wakeup pin enable for llwu_p1 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 1C0 wupe0 wakeup pin enable for llwu_p0 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 15.3.2 llwu pin enable 2 register (llwu_pe2) llwu_pe2 contains the field to enable and select the edge detect type for the external wakeup input pins llwu_p7-llwu_p4. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the introduction details for more information. address: 4007_c000h base + 1h offset = 4007_c001h bit 7 6 5 4 3 2 1 0 read wupe7 wupe6 wupe5 wupe4 write reset 0 0 0 0 0 0 0 0 llwu_pe2 field descriptions field description 7C6 wupe7 wakeup pin enable for llwu_p7 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection table continues on the next page... memory map/register definition kl04 sub-family reference manual, rev. 3.1, november 2012 222 freescale semiconductor, inc.
llwu_pe2 field descriptions (continued) field description 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 5C4 wupe6 wakeup pin enable for llwu_p6 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 3C2 wupe5 wakeup pin enable for llwu_p5 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 1C0 wupe4 wakeup pin enable for llwu_p4 enables and configures the edge detection for the wakeup pin. 00 external input pin disabled as wakeup input 01 external input pin enabled with rising edge detection 10 external input pin enabled with falling edge detection 11 external input pin enabled with any change detection 15.3.3 llwu module enable register (llwu_me) llwu_me contains the bits to enable the internal module flag as a wakeup input source for inputs mwuf7-mwuf0. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the introduction details for more information. address: 4007_c000h base + 2h offset = 4007_c002h bit 7 6 5 4 3 2 1 0 read wume7 wume6 wume5 wume4 wume3 wume2 wume1 wume0 write reset 0 0 0 0 0 0 0 0 chapter 15 low-leakage wakeup unit (llwu) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 223
llwu_me field descriptions field description 7 wume7 wakeup module enable for module 7 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source 6 wume6 wakeup module enable for module 6 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source 5 wume5 wakeup module enable for module 5 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source 4 wume4 wakeup module enable for module 4 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source 3 wume3 wakeup module enable for module 3 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source 2 wume2 wakeup module enable for module 2 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source 1 wume1 wakeup module enable for module 1 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source 0 wume0 wakeup module enable for module 0 enables an internal module as a wakeup source input. 0 internal module flag not used as wakeup source 1 internal module flag used as wakeup source memory map/register definition kl04 sub-family reference manual, rev. 3.1, november 2012 224 freescale semiconductor, inc.
15.3.4 llwu flag 1 register (llwu_f1) llwu_f1 contains the wakeup flags indicating which wakeup source caused the mcu to exit lls or vlls mode. for lls, this is the source causing the cpu interrupt flow. for vlls, this is the source causing the mcu reset flow. the external wakeup flags are read-only and clearing a flag is accomplished by a write of a 1 to the corresponding wufx bit. the wakeup flag (wufx), if set, will remain set if the associated wupex bit is cleared. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the introduction details for more information. address: 4007_c000h base + 3h offset = 4007_c003h bit 7 6 5 4 3 2 1 0 read wuf7 wuf6 wuf5 wuf4 wuf3 wuf2 wuf1 wuf0 write w1c w1c w1c w1c w1c w1c w1c w1c reset 0 0 0 0 0 0 0 0 llwu_f1 field descriptions field description 7 wuf7 wakeup flag for llwu_p7 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf7. 0 llwu_p7 input was not a wakeup source 1 llwu_p7 input was a wakeup source 6 wuf6 wakeup flag for llwu_p6 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf6. 0 llwu_p6 input was not a wakeup source 1 llwu_p6 input was a wakeup source 5 wuf5 wakeup flag for llwu_p5 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf5. 0 llwu_p5 input was not a wakeup source 1 llwu_p5 input was a wakeup source table continues on the next page... chapter 15 low-leakage wakeup unit (llwu) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 225
llwu_f1 field descriptions (continued) field description 4 wuf4 wakeup flag for llwu_p4 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf4. 0 llwu_p4 input was not a wakeup source 1 llwu_p4 input was a wakeup source 3 wuf3 wakeup flag for llwu_p3 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf3. 0 llwu_p3 input was not a wakeup source 1 llwu_p3 input was a wakeup source 2 wuf2 wakeup flag for llwu_p2 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf2. 0 llwu_p2 input was not a wakeup source 1 llwu_p2 input was a wakeup source 1 wuf1 wakeup flag for llwu_p1 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf1. 0 llwu_p1 input was not a wakeup source 1 llwu_p1 input was a wakeup source 0 wuf0 wakeup flag for llwu_p0 indicates that an enabled external wakeup pin was a source of exiting a low-leakage power mode. to clear the flag write a one to wuf0. 0 llwu_p0 input was not a wakeup source 1 llwu_p0 input was a wakeup source 15.3.5 llwu flag 3 register (llwu_f3) llwu_f3 contains the wakeup flags indicating which internal wakeup source caused the mcu to exit lls or vlls mode. for lls, this is the source causing the cpu interrupt flow. for vlls, this is the source causing the mcu reset flow. for internal peripherals that are capable of running in a low-leakage power mode, such as irtc or cmp modules, the flag from the associated peripheral is accessible as the mwufx bit. the flag will need to be cleared in the peripheral instead of writing a 1 to the mwufx bit. memory map/register definition kl04 sub-family reference manual, rev. 3.1, november 2012 226 freescale semiconductor, inc.
note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the introduction details for more information. address: 4007_c000h base + 4h offset = 4007_c004h bit 7 6 5 4 3 2 1 0 read mwuf7 mwuf6 mwuf5 mwuf4 mwuf3 mwuf2 mwuf1 mwuf0 write reset 0 0 0 0 0 0 0 0 llwu_f3 field descriptions field description 7 mwuf7 wakeup flag for module 7 indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 7 input was not a wakeup source 1 module 7 input was a wakeup source 6 mwuf6 wakeup flag for module 6 indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 6 input was not a wakeup source 1 module 6 input was a wakeup source 5 mwuf5 wakeup flag for module 5 indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 5 input was not a wakeup source 1 module 5 input was a wakeup source 4 mwuf4 wakeup flag for module 4 indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 4 input was not a wakeup source 1 module 4 input was a wakeup source 3 mwuf3 wakeup flag for module 3 indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 3 input was not a wakeup source 1 module 3 input was a wakeup source 2 mwuf2 wakeup flag for module 2 table continues on the next page... chapter 15 low-leakage wakeup unit (llwu) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 227
llwu_f3 field descriptions (continued) field description indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 2 input was not a wakeup source 1 module 2 input was a wakeup source 1 mwuf1 wakeup flag for module 1 indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 1 input was not a wakeup source 1 module 1 input was a wakeup source 0 mwuf0 wakeup flag for module 0 indicates that an enabled internal peripheral was a source of exiting a low-leakage power mode. to clear the flag, follow the internal peripheral flag clearing mechanism. 0 module 0 input was not a wakeup source 1 module 0 input was a wakeup source 15.3.6 llwu pin filter 1 register (llwu_filt1) llwu_filt1 is a control and status register that is used to enable/disable the digital filter 1 features for an external pin. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the introduction details for more information. address: 4007_c000h base + 5h offset = 4007_c005h bit 7 6 5 4 3 2 1 0 read filtf filte 0 filtsel write w1c reset 0 0 0 0 0 0 0 0 llwu_filt1 field descriptions field description 7 filtf filter detect flag indicates that the filtered external wakeup pin, selected by filtsel, was a source of exiting a low-leakage power mode. to clear the flag write a one to filtf. table continues on the next page... memory map/register definition kl04 sub-family reference manual, rev. 3.1, november 2012 228 freescale semiconductor, inc.
llwu_filt1 field descriptions (continued) field description 0 pin filter 1 was not a wakeup source 1 pin filter 1 was a wakeup source 6C5 filte digital filter on external pin controls the digital filter options for the external pin detect. 00 filter disabled 01 filter posedge detect enabled 10 filter negedge detect enabled 11 filter any edge detect enabled 4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3C0 filtsel filter pin select selects 1 out of the 16 wakeup pins to be muxed into the filter. 0000 select llwu_p0 for filter ... ... 1111 select llwu_p15 for filter 15.3.7 llwu pin filter 2 register (llwu_filt2) llwu_filt2 is a control and status register that is used to enable/disable the digital filter 2 features for an external pin. note this register is reset on chip reset not vlls and by reset types that trigger chip reset not vlls. it is unaffected by reset types that do not trigger chip reset not vlls. see the introduction details for more information. address: 4007_c000h base + 6h offset = 4007_c006h bit 7 6 5 4 3 2 1 0 read filtf filte 0 filtsel write w1c reset 0 0 0 0 0 0 0 0 llwu_filt2 field descriptions field description 7 filtf filter detect flag indicates that the filtered external wakeup pin, selected by filtsel, was a source of exiting a low-leakage power mode. to clear the flag write a one to filtf. table continues on the next page... chapter 15 low-leakage wakeup unit (llwu) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 229
llwu_filt2 field descriptions (continued) field description 0 pin filter 2 was not a wakeup source 1 pin filter 2 was a wakeup source 6C5 filte digital filter on external pin controls the digital filter options for the external pin detect. 00 filter disabled 01 filter posedge detect enabled 10 filter negedge detect enabled 11 filter any edge detect enabled 4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3C0 filtsel filter pin select selects 1 out of the 16 wakeup pins to be muxed into the filter. 0000 select llwu_p0 for filter ... ... 1111 select llwu_p15 for filter 15.4 functional description this on-chip peripheral module is called a low-leakage wakeup unit (llwu) module because it allows internal peripherals and external input pins as a source of wakeup from low-leakage modes. it is operational only in lls and vllsx modes. the llwu module contains pin enables for each external pin and internal module. for each external pin, the user can disable or select the edge type for the wakeup. type options are: ? falling-edge ? rising-edge ? either-edge when an external pin is enabled as a wakeup source, the pin must be configured as an input pin. the llwu implements optional 3-cycle glitch filters, based on the lpo clock. a detected external pin is required to remain asserted until the enabled glitch filter times out. additional latency of up to 2 cycles is due to synchronization, which results in a total of up to 5 cycles of delay before the detect circuit alerts the system to the wakeup or reset event when the filter function is enabled. two wakeup detect filters are available to detect up to two external pins. glitch filtering is not provided on the internal modules. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 230 freescale semiconductor, inc.
for internal module wakeup operation, the wumex bit enables the associated module as a wakeup source. 15.4.1 lls mode wakeup events triggered from either an external pin input or an internal module input result in a cpu interrupt flow to begin user code execution. 15.4.2 vlls modes in the case of a wakeup due to external pin or internal module wakeup, recovery is always via a reset flow and the rcm_srs[wakeup] is set indicating the low-leakage mode was active. state retention data is lost and i/o will be restored after pmc_regsc[ackiso] has been written. 15.4.3 initialization for an enabled peripheral wakeup input, the peripheral flag must be cleared by software before entering lls or vllsx mode to avoid an immediate exit from the mode. flags associated with external input pins, filtered and unfiltered, must also be cleared by software prior to entry to lls or vllsx mode. after enabling an external pin filter or changing the source pin, wait at least 5 lpo clock cycles before entering lls or vllsx mode to allow the filter to initialize. note after recovering from a vlls mode, user must restore chip configuration before clearing ackiso. in particular, pin configuration for enabled llwu wakeup pins must be restored to avoid any llwu flag from being falsely set when ackiso is cleared. the signal selected as a wakeup source pin must be a digital pin, as selected in the pin mux control. chapter 15 low-leakage wakeup unit (llwu) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 231
functional description kl04 sub-family reference manual, rev. 3.1, november 2012 232 freescale semiconductor, inc.
chapter 16 reset control module (rcm) 16.1 introduction this chapter describes the registers of the reset control module (rcm). the rcm implements many of the reset functions for the chip. see the chip's reset chapter for more information. 16.2 reset memory map and register descriptions the reset control module (rcm) registers provide reset status information and reset filter control. note the rcm registers can be written only in supervisor mode. write accesses in user mode are blocked and will result in a bus error. rcm memory map absolute address (hex) register name width (in bits) access reset value section/ page 4007_f000 system reset status register 0 (rcm_srs0) 8 r 82h 16.2.1/233 4007_f001 system reset status register 1 (rcm_srs1) 8 r 00h 16.2.2/235 4007_f004 reset pin filter control register (rcm_rpfc) 8 r/w 00h 16.2.3/236 4007_f005 reset pin filter width register (rcm_rpfw) 8 r/w 00h 16.2.4/237 16.2.1 system reset status register 0 (rcm_srs0) this register includes read-only status flags to indicate the source of the most recent reset. the reset state of these bits depends on what caused the mcu to reset. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 233
note the reset value of this register depends on the reset source: ? por (including lvd) 0x82 ? lvd (without por) 0x02 ? vlls mode wakeup due to reset pin assertion 0x41 ? vlls mode wakeup due to other wakeup sources 0x01 ? other reset a bit is set if its corresponding reset source caused the reset address: 4007_f000h base + 0h offset = 4007_f000h bit 7 6 5 4 3 2 1 0 read por pin wdog 0 loc lvd wakeup write reset 1 0 0 0 0 0 1 0 rcm_srs0 field descriptions field description 7 por power-on reset indicates a reset has been caused by the power-on detection logic. because the internal supply voltage was ramping up at the time, the low-voltage reset (lvd) status bit is also set to indicate that the reset occurred while the internal supply was below the lvd threshold. 0 reset not caused by por 1 reset caused by por 6 pin external reset pin indicates a reset has been caused by an active-low level on the external reset pin. 0 reset not caused by external reset pin 1 reset caused by external reset pin 5 wdog watchdog indicates a reset has been caused by the watchdog timer computer operating properly (cop) timing out. this reset source can be blocked by disabling the cop watchdog: write 00 to the sim's copc[copt] field. 0 reset not caused by watchdog timeout 1 reset caused by watchdog timeout 4C3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 loc loss-of-clock reset indicates a reset has been caused by a loss of external clock. the mcg clock monitor must be enabled for a loss of clock to be detected. refer to the detailed mcg description for information on enabling the clock monitor. 0 reset not caused by a loss of external clock. 1 reset caused by a loss of external clock. table continues on the next page... reset memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 234 freescale semiconductor, inc.
rcm_srs0 field descriptions (continued) field description 1 lvd low-voltage detect reset if the lvdre bit is set and the supply drops below the lvd trip voltage, an lvd reset occurs. this bit is also set by por. 0 reset not caused by lvd trip or por 1 reset caused by lvd trip or por 0 wakeup low leakage wakeup reset indicates a reset has been caused by an enabled llwu module wakeup source while the chip was in a low leakage mode. in lls mode, the reset pin is the only wakeup source that can cause this reset. any enabled wakeup source in a vllsx mode causes a reset. this bit is cleared by any reset except wakeup. 0 reset not caused by llwu module wakeup source 1 reset caused by llwu module wakeup source 16.2.2 system reset status register 1 (rcm_srs1) this register includes read-only status flags to indicate the source of the most recent reset. the reset state of these bits depends on what caused the mcu to reset. note the reset value of this register depends on the reset source: ? por (including lvd) 0x00 ? lvd (without por) 0x00 ? vlls mode wakeup 0x00 ? other reset a bit is set if its corresponding reset source caused the reset address: 4007_f000h base + 1h offset = 4007_f001h bit 7 6 5 4 3 2 1 0 read 0 0 sackerr 0 mdm_ap sw lockup 0 write reset 0 0 0 0 0 0 0 0 rcm_srs1 field descriptions field description 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... chapter 16 reset control module (rcm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 235
rcm_srs1 field descriptions (continued) field description 5 sackerr stop mode acknowledge error reset indicates that after an attempt to enter stop mode, a reset has been caused by a failure of one or more peripherals to acknowledge within approximately one second to enter stop mode. 0 reset not caused by peripheral failure to acknowledge attempt to enter stop mode 1 reset caused by peripheral failure to acknowledge attempt to enter stop mode 4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 mdm_ap mdm-ap system reset request indicates a reset has been caused by the host debugger system setting of the system reset request bit in the mdm-ap control register. 0 reset not caused by host debugger system setting of the system reset request bit 1 reset caused by host debugger system setting of the system reset request bit 2 sw software indicates a reset has been caused by software setting of sysresetreq bit in application interrupt and reset control register in the arm core. 0 reset not caused by software setting of sysresetreq bit 1 reset caused by software setting of sysresetreq bit 1 lockup core lockup indicates a reset has been caused by the arm core indication of a lockup event. 0 reset not caused by core lockup event 1 reset caused by core lockup event 0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 16.2.3 reset pin filter control register (rcm_rpfc) note the reset values of bits 2-0 are for chip por only. they are unaffected by other reset types. note the bus clock filter is reset when disabled or when entering stop mode. the lpo filter is reset when disabled . address: 4007_f000h base + 4h offset = 4007_f004h bit 7 6 5 4 3 2 1 0 read 0 rstfltss rstfltsrw write reset 0 0 0 0 0 0 0 0 reset memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 236 freescale semiconductor, inc.
rcm_rpfc field descriptions field description 7C3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 rstfltss reset pin filter select in stop mode selects how the reset pin filter is enabled in stop and vlps modes , and also during lls and vlls modes. on exit from vlls mode, this bit should be reconfigured before clearing ackiso in the pmc. 0 all filtering disabled 1 lpo clock filter enabled 1C0 rstfltsrw reset pin filter select in run and wait modes selects how the reset pin filter is enabled in run and wait modes. 00 all filtering disabled 01 bus clock filter enabled for normal operation 10 lpo clock filter enabled for normal operation 11 reserved 16.2.4 reset pin filter width register (rcm_rpfw) note the reset values of the bits in the rstfltsel field are for chip por only. they are unaffected by other reset types. address: 4007_f000h base + 5h offset = 4007_f005h bit 7 6 5 4 3 2 1 0 read 0 rstfltsel write reset 0 0 0 0 0 0 0 0 rcm_rpfw field descriptions field description 7C5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4C0 rstfltsel reset pin filter bus clock select selects the reset pin bus clock filter width. 00000 bus clock filter count is 1 00001 bus clock filter count is 2 00010 bus clock filter count is 3 00011 bus clock filter count is 4 00100 bus clock filter count is 5 table continues on the next page... chapter 16 reset control module (rcm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 237
rcm_rpfw field descriptions (continued) field description 00101 bus clock filter count is 6 00110 bus clock filter count is 7 00111 bus clock filter count is 8 01000 bus clock filter count is 9 01001 bus clock filter count is 10 01010 bus clock filter count is 11 01011 bus clock filter count is 12 01100 bus clock filter count is 13 01101 bus clock filter count is 14 01110 bus clock filter count is 15 01111 bus clock filter count is 16 10000 bus clock filter count is 17 10001 bus clock filter count is 18 10010 bus clock filter count is 19 10011 bus clock filter count is 20 10100 bus clock filter count is 21 10101 bus clock filter count is 22 10110 bus clock filter count is 23 10111 bus clock filter count is 24 11000 bus clock filter count is 25 11001 bus clock filter count is 26 11010 bus clock filter count is 27 11011 bus clock filter count is 28 11100 bus clock filter count is 29 11101 bus clock filter count is 30 11110 bus clock filter count is 31 11111 bus clock filter count is 32 reset memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 238 freescale semiconductor, inc.
chapter 17 bit manipulation engine (bme) 17.1 introduction the bit manipulation engine (bme) provides hardware support for atomic read-modify- write memory operations to the peripheral address space in cortex-m0+ based microcontrollers. this architectural capability is also known as "decorated storage" as it defines a mechanism for providing additional semantics for load and store operations to memory-mapped peripherals beyond just the reading and writing of data values to the addressed memory locations. in the bme definition, the "decoration", that is, the additional semantic information, is encoded into the peripheral address used to reference the memory. by combining the basic load and store instructions of the cortex-m instruction set architecture (v6m, v7m) with the concept of decorated storage provided by the bme, the resulting implementation provides a robust and efficient read-modify-write capability to this class of ultra low-end microcontrollers. the resulting architectural capability defined by this core platform function is targeted at the manipulation of n-bit fields in peripheral registers and is consistent with i/o hardware addressing in the embedded c standard. for most bme commands, a single core read or write bus cycle is converted into an atomic read-modify-write, that is, an indivisible "read followed by a write" bus sequence. bme decorated references are only available on system bus transactions generated by the processor core and targeted at the standard 512 kb peripheral address space based at 0x4000_0000 1 . the decoration semantic is embedded into address bits[28:19], creating a 448 mb space at addresses 0x4400_0000 - 0x5fff_ffff; these bits are stripped out of the actual address sent to the peripheral bus controller and used by the bme to define and control its operation. 1. to be perfectly accurate, the peripheral address space occupies a 516 kb region: 512 kb based at 0x4000_0000 plus a 4 kb space based at 0x400f_f000 for gpio accesses. this organization provides compatibility with the kinetis k family. attempted accesses to the memory space located between 0x4008_0000 - 0x400e_ffff are error terminated due to an illegal address. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 239
17.1.1 overview the following figure is a generic block diagram of the processor core and platform for this class of ultra low-end microcontrollers. axbs cm0+ core platform fmc ld/st dbg nvic fetch cortex-m0+ core mtb port ahb bus agu mul ram array 32 dec rn shft alu dma_4ch nvm array pram 32 rgpio pbridge bme 32 io port slave peripherals alt-master -lite m0 s1 s2 s0 m3 m2 note: bme can be accessed only by the core. figure 17-1. generic cortex-m0+ core platform block diagram as shown in the block diagram, the bme module interfaces to a crossbar switch ahb slave port as its primary input and sources an ahb bus output to the peripheral bridge (pbridge) controller. the bme hardware microarchitecture is a 2-stage pipeline design matching the protocol of the amba-ahb system bus interfaces. the pbridge module converts the ahb system bus protocol into the ips/apb protocol used by the attached slave peripherals. 17.1.2 features the key features of the bme include: ? lightweight implementation of decorated storage for peripheral address space ? additional access semantics encoded into the reference address introduction kl04 sub-family reference manual, rev. 3.1, november 2012 240 freescale semiconductor, inc.
? resides between a crossbar switch slave port and a peripheral bridge bus controller ? 2-stage pipeline design matching the ahb system bus protocol ? combinationally passes non-decorated accesses to peripheral bridge bus controller ? conversion of decorated loads and stores from processor core into atomic read- modify-writes ? decorated loads support unsigned bit field extracts, load-and-{set,clear}-1bit operations ? decorated stores support bit field inserts, logical and, or and xor operations ? support for byte, halfword and word-sized decorated operations ? supports minimum signal toggling on ahb output bus to reduce power dissipation 17.1.3 modes of operation the bme module does not support any special modes of operation. as a memory- mapped device located on a crossbar slave ahb system bus port, bme responds based strictly on memory addresses for accesses to the connected peripheral bridge bus controller. all functionality associated with the bme module resides in the core platform's clock domain; this includes its connections with the crossbar slave port and the pbridge bus controller. 17.2 external signal description the bme module does not directly support any external interfaces. the internal interfaces include two standard ahb buses with 32-bit datapath widths: the primary input from the appropriate crossbar slave port (mx_h) and the primary output to the pbridge bus controller (sx_h). note the signal directions are defined by the bme's view and are labeled based on the dominant direction. accordingly, the mx_h ahb bus is the primary input, even though there are certain data phase signals (mx_h{rdata, ready, resp}) which are outputs from bme. likewise, the sx_h ahb bus is the primary output even though there are specific data phase signals (sx_h{rdata, ready, resp}) which are inputs to bme. chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 241
17.3 memory map and register definition the bme module provides a memory-mapped capability and does not include any programming model registers. the exact set of functions supported by the bme are detailed in the functional description . the peripheral address space occupies a 516 kb region: 512 kb based at 0x4000_0000 plus a 4 kb space based at 0x400f_f000 for gpio accesses; the decorated address space is mapped to the 448 mb region located at 0x4400_0000 - 0x5fff_ffff. 17.4 functional description this section details the specific functions supported by the bme. recall the combination of the basic load and store instructions of the cortex-m instruction set architecture (v6m, v7m) plus the concept of decorated storage provided by the bme, the resulting implementation provides a robust and efficient read-modify-write capability to this class of ultra low-end microcontrollers. the resulting architectural capability defined by this core platform function is targeted at the manipulation of n-bit fields in peripheral registers and is consistent with i/o hardware addressing in the embedded c standard. for most bme commands, a single core read or write bus cycle is converted into an atomic read-modify-write, that is, an indivisible "read followed by a write" bus sequence. consider decorated store operations first, then decorated loads. 17.4.1 bme decorated stores the functions supported by the bme's decorated stores include three logical operators (and, or, xor) plus a bit field insert. for all these operations, bme converts a single decorated ahb store transaction into a 2-cycle atomic read-modify-write sequence, where the combined read-modify operation is performed in the first ahb data phase, and then the write is performed in the second ahb data phase. a generic timing diagram of a decorated store showing a bit field insert operation is shown as follows: memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 242 freescale semiconductor, inc.
x x+1 x+2 x+3 next 5..v_wxyz next wdata next 400v_wxyz 400v_wxyz next next 5..v_wxyz wdata bfi rdata wdata bfi rdata next rdata cycle ruler hclk bme ahb input bus mx_haddr mx_hattr mx_hwrite mx_hwdata mx_hrdata mx_hready bme ahb output bus sx_haddr sx_hattr sx_hwrite sx_hwdata sx_hrdata sx_hready bme states + datapath control_state_dp1 control_state_dp2 reg_addr_data_dp figure 17-2. decorated store: bit field insert timing diagram all the decorated store operations follow the same execution template shown in the figure above, a 2-cycle read-modify-write operation: ? cycle x, 1st ahb address phase: write from input bus (mx_h) is translated into a read operation on the output bus (sx_h) using the actual memory address (with the decoration removed) and then captured in a register (reg_addr_data_dp) ? cycle x+1, 2nd ahb address phase: write access with the registered (but actual) memory address is output (sx_h) ? cycle x+1, 1st ahb data phase: memory read data (sx_hrdata) is modified using the input bus write data (mx_hwdata) and the function defined by the decoration and captured in a data register (reg_addr_data_dp); the input bus cycle is stalled (mx_hready = 0) ? cycle x+2, 2nd ahb data phase: registered write data is sourced onto the output write data bus (sx_hwdata) chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 243
note any wait states inserted by the peripheral slave device (sx_hready = 0) are simply passed through the bme back to the master input bus, stalling the ahb transaction cycle for cycle. 17.4.1.1 decorated store logical and (and) this command performs an atomic read-modify-write of the referenced memory location. first, the location is read; it is then modified by performing a logical and operation using the write data operand sourced for the system bus cycle; finally, the result of the and operation is written back into the referenced memory location. the data size is specified by the write operation and can be byte (8-bit), halfword (16-bit) or word (32-bit). the core performs the required write data lane replication on byte and halfword transfers. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ioandb 0 1 0 0 0 1 - - - - - - mem_addr ioandh 0 1 0 0 0 1 - - - - - - mem_addr 0 ioandw 0 1 0 0 0 1 - - - - - - mem_addr 0 0 figure 17-3. decorated store address: logical and where addr[28:26] = 001 specifies the and operation, and mem_addr[19:0] specifies the address offset into the peripheral space based at 0x4000_0000. the "-" indicates an address bit "don't care". the decorated and write operation is defined in the following pseudo-code as: ioand(accessaddress, wdata) // decorated store and tmp = mem[accessaddress & 0xe00fffff, size] // memory read tmp = tmp & wdata // modify mem[accessaddress & 0xe00fffff, size] = tmp // memory write where the operand size is defined as b(yte, 8-bit), h(alfword, 16-bit) and w(ord, 32- bit). this notation is used throughout the document. in the cycle definition tables, the notation ahb_ap and ahb_dp refers to the address and data phases of the bme ahb transaction. the cycle-by-cycle bme operations are detailed in the following table. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 244 freescale semiconductor, inc.
table 17-1. cycle definitions of decorated store: logical and pipeline stage cycle x x+1 x+2 bme ahb_ap forward addr to memory; decode decoration; convert master_wt to slave_rd; capture address, attributes recirculate captured addr + attr to memory as slave_wt bme ahb_dp perform memory read; form (rdata & wdata) and capture destination data in register perform write sending registered data to memory 17.4.1.2 decorated store logical or (or) this command performs an atomic read-modify-write of the referenced memory location. first, the location is read; it is then modified by performing a logical or operation using the write data operand sourced for the system bus cycle; finally, the result of the or operation is written back into the referenced memory location. the data size is specified by the write operation and can be byte (8 bit), halfword (16 bit) or word (32 bit). the core performs the required write data lane replication on byte and halfword transfers. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ioorb 0 1 0 0 1 0 - - - - - - mem_addr ioorh 0 1 0 0 1 0 - - - - - - mem_addr 0 ioorw 0 1 0 0 1 0 - - - - - - mem_addr 0 0 figure 17-4. decorated address store: logical or where addr[28:26] = 010 specifies the or operation, and mem_addr[19:0] specifies the address offset into the peripheral space based at 0x4000_0000. the "-" indicates an address bit "don't care". the decorated or write operation is defined in the following pseudo-code as: ioor(accessaddress, wdata) // decorated store or tmp = mem[accessaddress & 0xe00fffff, size] // memory read tmp = tmp | wdata // modify mem[accessaddress & 0xe00fffff, size] = tmp // memory write the cycle-by-cycle bme operations are detailed in the following table chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 245
table 17-2. cycle definitions of decorated store: logical or pipeline stage cycle x x+1 x+2 bme ahb_ap forward addr to memory; decode decoration; convert master_wt to slave_rd; capture address, attributes recirculate captured addr + attr to memory as slave_wt bme ahb_dp perform memory read; form (rdata | wdata) and capture destination data in register perform write sending registered data to memory 17.4.1.3 decorated store: logical xor (xor) this command performs an atomic read-modify-write of the referenced memory location. first, the location is read; it is then modified by performing a logical xor (exclusive- or) operation using the write data operand sourced for the system bus cycle; finally, the result of the xor operation is written back into the referenced memory location. the data size is specified by the write operation and can be byte (8-bit), halfword (16-bit) or word (32-bit). the core performs the required write data lane replication on byte and halfword transfers. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ioxorb 0 1 0 0 1 1 - - - - - - mem_addr ioxorh 0 1 0 0 1 1 - - - - - - mem_addr 0 ioxorw 0 1 0 0 1 1 - - - - - - mem_addr 0 0 figure 17-5. decorated address store: logical xor where addr[28:26] = 011 specifies the xor operation, and mem_addr[19:0] specifies the address offset into the peripheral space based at 0x4000_0000. the "-" indicates an address bit "don't care". the decorated xor write operation is defined in the following pseudo-code as: ioxor(accessaddress, wdata) // decorated store xor tmp = mem[accessaddress & 0xe00fffff, size] // memory read tmp = tmp ^ wdata // modify mem[accessaddress & 0xe00fffff, size] = tmp // memory write the cycle-by-cycle bme operations are detailed in the following table. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 246 freescale semiconductor, inc.
table 17-3. cycle definitions of decorated store: logical xor pipeline stage cycle x x+1 x+2 bme ahb_ap forward addr to memory; decode decoration; convert master_wt to slave_rd; capture address, attributes recirculate captured addr + attr to memory as slave_wt bme ahb_dp perform memory read; form (rdata ^ wdata) and capture destination data in register perform write sending registered data to memory 17.4.1.4 decorated store bit field insert (bfi) this command inserts a bit field contained in the write data operand, defined by lsb position (b) and the bit field width (w+1), into the memory "container" defined by the access size associated with the store instruction using an atomic read-modify-write sequence. the data size is specified by the write operation and can be byte (8-bit), halfword (16-bit) or word (32-bit). note for the word sized operation, the maximum bit field width is 16 bits. the core performs the required write data lane replication on byte and halfword transfers. the bfi operation can be used to insert a single bit into a peripheral. for this case, the w field is simply set to 0, indicating a bit field width of 1. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 iobfib 0 1 0 1 - - b b b - w w w mem_addr iobfih 0 1 0 1 - b b b b w w w w mem_addr 0 iobfiw 0 1 0 1 b b b b b w w w w mem_addr 0 0 figure 17-6. decorated address store: bit field insert where addr[28] = 1 signals a bfi operation, addr[27:23] is "b", the lsb identifier, addr[22:19] is "w", the bit field width minus 1 identifier, and addr[18:0] specifies the address offset into the peripheral space based at 0x4000_0000. the "-" indicates an address bit "don't care". note, unlike the other decorated store operations, bfi uses addr[19] as the least significant bit in the "w" specifier and not as an address bit. the decorated bfi write operation is defined in the following pseudo-code as: iobfi(accessaddress, wdata) // decorated bit field insert tmp = mem[accessaddress & 0xe007ffff, size] // memory read mask = ((1 << (w+1)) - 1) << b // generate bit mask chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 247
tmp = tmp & ~mask // modify | wdata & mask mem[accessaddress & 0xe007ffff, size] = tmp // memory write the write data operand (wdata) associated with the store instruction contains the bit field to be inserted. it must be properly aligned within a right-justified container, that is, within the lower 8 bits for a byte operation, the lower 16 bits for a halfword or the entire 32 bits for a word operation. to illustrate, consider the following example of the insertion of the 3-bit field "xyz" into an 8-bit memory container, initially set to "abcd_efgh". for all cases, w is 2, signaling a bit field width of 3. if b = 0 and the decorated store (strb) rt register[7:0] = ----_-xyz, then destination is "abcd_exyz" if b = 1 and the decorated store (strb) rt register[7:0] = ----_xyz-, then destination is "abcd_xyzh" if b = 2 and the decorated store (strb) rt register[7:0] = ---x_yz--, then destination is "abcx_yzgh" if b = 3 and the decorated store (strb) rt register[7:0] = --xy_z---, then destination is "abxy_zfgh" if b = 4 and the decorated store (strb) rt register[7:0] = -xyz_----, then destination is "axyz_efgh" if b = 5 and the decorated store (strb) rt register[7:0] = xyz-_----, then destination is "xyzd_efgh" if b = 6 and the decorated store (strb) rt register[7:0] = yz--_----, then destination is "yzcd_efgh" if b = 7 and the decorated store (strb) rt register[7:0] = z---_----, then destination is "zbcd_efgh" note from the example, when the starting bit position plus the field width exceeds the container size, only part of the source bit field is inserted into the destination memory location. stated differently, if (b + w+1) > container_width, only the low-order "container_width - b" bits are actually inserted. the cycle-by-cycle bme operations are detailed in the following table. table 17-4. cycle definitions of decorated store: bit field insert pipeline stage cycle x x+1 x+2 bme ahb_ap forward addr to memory; decode decoration; convert master_wt to slave_rd; capture address, attributes recirculate captured addr + attr to memory as slave_wt bme ahb_dp perform memory read; form bit mask; form bitwise ((mask) ? wdata : rdata)) and capture destination data in register perform write sending registered data to memory functional description kl04 sub-family reference manual, rev. 3.1, november 2012 248 freescale semiconductor, inc.
17.4.2 bme decorated loads the functions supported by the bme's decorated loads include two single-bit load-and- {set, clear} operators plus unsigned bit field extracts. for the two load-and-{set, clear} operations, bme converts a single decorated ahb load transaction into a 2-cycle atomic read-modify-write sequence, where the combined read-modify operations are performed in the first ahb data phase, and then the write is performed in the second ahb data phase as the original read data is returned to the processor core. for an unsigned bit field extract, the decorated load transaction is stalled for one cycle in the bme as the data field is extracted, then aligned and returned to the processor in the 2nd ahb data phase. this is the only decorated transaction that is not an atomic read-modify-write, as it is a simple data read. a generic timing diagram of a decorated load showing a load-and-set 1-bit operation is shown as follows. x x+1 x+2 x+3 next 4c.v_wxyz next next 400v_wxyz 400v_wxyz next next 4c.v_wxyz rdata + 1bit rdata + 1bit next rdata orig_1bit cycle ruler hclk bme ahb input bus mx_haddr mx_hattr mx_hwrite mx_hwdata mx_hrdata mx_hready bme ahb output bus sx_haddr sx_hattr sx_hwrite sx_hwdata sx_hrdata sx_hready bme states + datapath control_state_dp1 control_state_dp2 reg_addr_data_dp figure 17-7. decorated load: load-and-set 1-bit field insert timing diagram decorated load-and-{set, clear} 1-bit operations follow the execution template shown in the above figure: a 2-cycle read-modify-write operation: chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 249
? cycle x, 1st ahb address phase: read from input bus is translated into a read operation on the output bus with the actual memory address (with the decoration removed) and then captured in a register ? cycle x+1, 2nd ahb address phase: write access with the registered (but actual) memory address is output ? cycle x+1, 1st ahb data phase: the "original" 1-bit memory read data is captured in a register, while the 1-bit field is set or clear based on the function defined by the decoration with the modified data captured in a register; the input bus cycle is stalled ? cycle x+2, 2nd ahb data phase: the selected original 1-bit is right justified, zero filled and then driven onto the input read data bus, while the registered write data is sourced onto the output write data bus note any wait states inserted by the peripheral slave device (sx_hready = 0) are simply passed through the bme back to the master input bus, stalling the ahb transaction cycle for cycle. a generic timing diagram of a decorated load showing an unsigned bit field operation is shown in the following figure. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 250 freescale semiconductor, inc.
1 2 3 4 next5..v_wxyz next next 400v_wxyz next next 5..v_wxyz rdata next rdata ubfx cycle ruler hclk bme ahb input bus mx_haddr mx_hattr mx_hwrite mx_hwdata mx_hrdata mx_hready bme ahb output bus sx_haddr sx_hattr sx_hwrite sx_hwdata sx_hrdata sx_hready bme states + datapath control_state_dp1 control_state_dp2 reg_addr_data_dp figure 17-8. decorated load: unsigned bit field insert timing diagram the decorated unsigned bit field extract follows the same execution template shown in the above figure, a 2-cycle read operation: ? cycle x, 1st ahb address phase: read from input bus is translated into a read operation on the output bus with the actual memory address (with the decoration removed) and then captured in a register ? cycle x+1, 2nd ahb address phase: idle cycle ? cycle x+1, 1st ahb data phase: a bit mask is generated based on the starting bit position and the field width; the mask is and'ed with the memory read data to isolate the bit field; the resulting data is captured in a data register; the input bus cycle is stalled ? cycle x+2, 2nd ahb data phase: registered data is logically right shifted for proper alignment and driven onto the input read data bus note any wait states inserted by the peripheral slave device (sx_hready = 0) are simply passed through the bme back to the master input bus, stalling the ahb transaction cycle for cycle. chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 251
17.4.2.1 decorated load load-and-clear 1 bit (lac1) this command loads a 1-bit field defined by the lsb position (b) into the core's general purpose destination register (rt) and zeroes the bit in the memory space after performing an atomic read-modify-write sequence. the extracted one bit data field from the memory address is right justified and zero filled in the operand returned to the core. the data size is specified by the read operation and can be byte (8-bit), halfword (16-bit) or word (32-bit). 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 iolac1b 0 1 0 0 1 0 - - b b b - mem_addr iolac1h 0 1 0 0 1 0 - b b b b - mem_addr 0 iolac1w 0 1 0 0 1 0 b b b b b - mem_addr 0 0 figure 17-9. decorated load address: load-and-clear 1 bit where addr[28:26] = 010 specifies the load-and-clear 1 bit operation, addr[25:21] is "b", the bit identifier, and mem_addr[19:0] specifies the address offset into the peripheral space based at 0x4000_0000. the "-" indicates an address bit "don't care". the decorated load-and-clear 1 bit read operation is defined in the following pseudo- code as: rdata = iolac1(accessaddress) // decorated load-and-clear 1 tmp = mem[accessaddress & 0xe00fffff, size] // memory read mask = 1 << b // generate bit mask rdata = (tmp & mask) >> b // read data returned to core tmp = tmp & ~mask // modify mem[accessaddress & 0xe00fffff, size] = tmp // memory write the cycle-by-cycle bme operations are detailed in the following table. table 17-5. cycle definitions of decorated load: load-and-clear 1 bit pipeline stage cycle x x+1 x+2 bme ahb_ap forward addr to memory; decode decoration; capture address, attributes recirculate captured addr + attr to memory as slave_wt bme ahb_dp perform memory read; form bit mask; extract bit from rdata; form (rdata & ~mask) and capture destination data in register return extracted bit to master; perform write sending registered data to memory functional description kl04 sub-family reference manual, rev. 3.1, november 2012 252 freescale semiconductor, inc.
17.4.2.2 decorated load: load-and-set 1 bit (las1) this command loads a 1-bit field defined by the lsb position (b) into the core's general purpose destination register (rt) and sets the bit in the memory space after performing an atomic read-modify-write sequence. the extracted one bit data field from the memory address is right justified and zero filled in the operand returned to the core. the data size is specified by the read operation and can be byte (8-bit), halfword (16-bit) or word (32-bit). 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 iolas1b 0 1 0 0 1 1 - - b b b - mem_addr iolas1h 0 1 0 0 1 1 - b b b b - mem_addr 0 iolas1w 0 1 0 0 1 1 b b b b b - mem_addr 0 0 figure 17-10. decorated load address: load-and-set 1 bit where addr[28:26] = 011 specifies the load-and-set 1 bit operation, addr[25:21] is "b", the bit identifier, and mem_addr[19:0] specifies the address offset into the peripheral space based at 0x4000_0000. the "-" indicates an address bit "don't care". the decorated load-and-set 1 bit read operation is defined in the following pseudo-code as: rdata = iolas1(accessaddress) // decorated load-and-set 1 tmp = mem[accessaddress & 0xe00fffff, size] // memory read mask = 1 << b // generate bit mask rdata = (tmp & mask) >> b // read data returned to core tmp = tmp | mask // modify mem[accessaddress & 0xe00fffff, size] = tmp // memory write the cycle-by-cycle bme operations are detailed in the following table. table 17-6. cycle definitions of decorated load: load-and-set 1-bit pipeline stage cycle x x+1 x+2 bme ahb_ap forward addr to memory; decode decoration; capture address, attributes recirculate captured addr + attr to memory as slave_wt bme ahb_dp perform memory read; form bit mask; extract bit from rdata; form (rdata | mask) and capture destination data in register return extracted bit to master; perform write sending registered data to memory chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 253
17.4.2.3 decorated load unsigned bit field extract (ubfx) this command extracts a bit field defined by lsb position (b) and the bit field width (w +1) from the memory "container" defined by the access size associated with the load instruction using a 2-cycle read sequence. the extracted bit field from the memory address is right justified and zero filled in the operand returned to the core. recall this is the only decorated operation that does not perform a memory write, that is, ubfx only performs a read. the data size is specified by the write operation and can be byte (8-bit), halfword (16-bit) or word (32-bit). note for the word sized operation, the maximum bit field width is 16 bits. the use of a ubfx operation is recommended to extract a single bit from a peripheral. for this case, the w field is simply set to 0, indicating a bit field width of 1. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ioubfxb 0 1 0 1 - - b b b - w w w mem_addr ioubfxh 0 1 0 1 - b b b b w w w w mem_addr 0 ioubfxw 0 1 0 1 b b b b b w w w w mem_addr 0 0 figure 17-11. decorated load address: unsigned bit field extract where addr[28] = 1 specifies the unsigned bit field extract operation, addr[27:23] is "b", the lsb identifier, addr[22:19] is "w", the bit field width minus 1 identifier, and mem_addr[18:0] specifies the address offset into the peripheral space based at 0x4000_0000. the "-" indicates an address bit "don't care". note, unlike the other decorated load operations, ubfx uses addr[19] as the least significant bit in the "w" specifier and not as an address bit. the decorated unsigned bit field extract read operation is defined in the following pseudo-code as: rdata = ioubfx(accessaddress) // unsigned bit field extract tmp = mem[accessaddress & 0xe007ffff, size] // memory read mask = ((1 << (w+1)) - 1) << b // generate bit mask rdata = (tmp & mask) >> b // read data returned to core like the bfi operation, when the starting bit position plus the field width exceeds the container size, only part of the source bit field is extracted from the destination memory location. stated differently, if (b + w+1) > container_width, only the low-order "container_width - b" bits are actually extracted. the cycle-by-cycle bme operations are detailed in the following table. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 254 freescale semiconductor, inc.
table 17-7. cycle definitions of decorated load: unsigned bit field extract pipeline stage cycle x x+1 x+2 bme ahb_ap forward addr to memory; decode decoration; capture address, attributes idle ahb address phase bme ahb_dp perform memory read; form bit mask; form (rdata & mask) and capture destination data in register logically right shift registered data; return justified rdata to master 17.4.3 additional details on decorated addresses and gpio accesses as previously noted, the peripheral address space occupies a 516 kb region: 512 kb based at 0x4000_0000 plus a 4 kb space based at 0x400f_f000 for gpio accesses. this memory layout provides compatibility with the kinetis k family and provides 129 address "slots", each 4 kb in size. the gpio address space is multiply-mapped by the hardware: it appears at the "standard" system address 0x400f_f000 and is physically located in the address slot corresponding to address 0x4000_f000. decorated loads and stores create a slight complication involving accesses to the gpio. recall the use of address[19] varies by decorated operation; for and, or, xor, lac1 and las1, this bit functions as a true address bit, while for bfi and ubfx, this bit defines the least significant bit of the "w" bit field specifier. as a result, undecorated gpio references and decorated and, or, xor, lac1 and las1 operations can use the standard 0x400f_f000 base address, while decorated bfi and ubfx operations must use the alternate 0x4000_f000 base address. another implementation can simply use 0x400f_f000 as the base address for all undecorated gpio accesses and 0x4000_f000 as the base address for all decorated accesses. both implementations are supported by the hardware. table 17-8. decorated peripheral and gpio address details peripheral address space description 0x4000_0000 - 0x4007_ffff undecorated (normal) peripheral accesses 0x4008_0000 - 0x400f_efff illegal addresses; attempted references are aborted and error terminated 0x400f_f000 - 0x400f_ffff undecorated (normal) gpio accesses using standard address 0x4010_0000 - 0x43ff_ffff illegal addresses; attempted references are aborted and error terminated table continues on the next page... chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 255
table 17-8. decorated peripheral and gpio address details (continued) peripheral address space description 0x4400_0000 - 0x4fff_ffff decorated and, or, xor, lac1, las1 references to peripherals and gpio based at either 0x4000_f000 or 0x400f_f000 0x5000_0000 - 0x5fff_ffff decorated bfi, ubfx references to peripherals and gpio only based at 0x4000_f000 17.5 application information in this section, gnu assembler macros with c expression operands are presented as examples of the required instructions to perform decorated operations. this section specifically presents a partial bme.h file defining the assembly language expressions for decorated logical stores: and, or and xor. comparable functions for bfi and the decorated loads are more complex and available in the complete bme header file. these macros use the same function names presented in functional description . #define ioandw(addr,wdata) \ __asm("ldr r3, =(1<<26);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "str r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioandh(addr,wdata) \ __asm("ldr r3, =(1<<26);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "strh r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioandb(addr,wdata) \ __asm("ldr r3, =(1<<26);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "strb r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioorw(addr,wdata) \ __asm("ldr r3, =(1<<27);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "str r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioorh(addr,wdata) \ __asm("ldr r3, =(1<<27);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "strh r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioorb(addr,wdata) \ __asm("ldr r3, =(1<<27);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "strb r2, [r3];" \ application information kl04 sub-family reference manual, rev. 3.1, november 2012 256 freescale semiconductor, inc.
:: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioxorw(addr,wdata) \ __asm("ldr r3, =(3<<26);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "str r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioxorh(addr,wdata) \ __asm("ldr r3, =(3<<26);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "strh r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); #define ioxorb(addr,wdata) \ __asm("ldr r3, =(3<<26);" \ "orr r3, %[addr];" \ "mov r2, %[wdata];" \ "strb r2, [r3];" \ :: [addr] "r" (addr), [wdata] "r" (wdata) : "r2", "r3"); chapter 17 bit manipulation engine (bme) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 257
application information kl04 sub-family reference manual, rev. 3.1, november 2012 258 freescale semiconductor, inc.
chapter 18 miscellaneous control module (mcm) 18.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the miscellaneous control module (mcm) provides a myriad of miscellaneous control functions. 18.1.1 features the mcm includes the following features: ? program-visible information on the platform configuration ? crossbar master arbitration policy selection ? flash controller speculation buffer and cache configurations 18.2 memory map/register descriptions the memory map and register descriptions below describe the registers using byte addresses. mcm memory map absolute address (hex) register name width (in bits) access reset value section/ page f000_3008 crossbar switch (axbs) slave configuration (mcm_plasc) 16 r 0007h 18.2.1/260 table continues on the next page... kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 259
mcm memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page f000_300a crossbar switch (axbs) master configuration (mcm_plamc) 16 r 0005h 18.2.2/261 f000_300c platform control register (mcm_placr) 32 r/w 0000_0000h 18.2.3/261 f000_3040 compute operation control register (mcm_cpo) 32 r/w 0000_0000h 18.2.4/264 18.2.1 crossbar switch (axbs) slave configuration (mcm_plasc) plasc is a 16-bit read-only register identifying the presence/absence of bus slave connections to the devices crossbar switch. address: f000_3000h base + 8h offset = f000_3008h bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 read 0 asc write reset 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 mcm_plasc field descriptions field description 15C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7C0 asc each bit in the asc field indicates whether there is a corresponding connection to the crossbar switch's slave input port. 0 a bus slave connection to axbs input port n is absent 1 a bus slave connection to axbs input port n is present memory map/register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 260 freescale semiconductor, inc.
18.2.2 crossbar switch (axbs) master configuration (mcm_plamc) plamc is a 16-bit read-only register identifying the presence/absence of bus master connections to the device's crossbar switch. address: f000_3000h base + ah offset = f000_300ah bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 read 0 amc write reset 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 mcm_plamc field descriptions field description 15C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7C0 amc each bit in the amc field indicates whether there is a corresponding connection to the axbs master input port. 0 a bus master connection to axbs input port n is absent 1 a bus master connection to axbs input port n is present 18.2.3 platform control register (mcm_placr) the placr register selects the arbitration policy for the crossbar masters and configures the flash memory controller. the speculation buffer and cache in the flash memory controller is configurable via mcm_placr[15:10]. the speculation buffer is enabled only for instructions after reset. it is possible to have these states for the speculation buffer: dfcs efds description 0 0 speculation buffer is on for instruction and off for data. 0 1 speculation buffer is on for instruction and on for data. 1 x speculation buffer is off. chapter 18 miscellaneous control module (mcm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 261
the cache in flash controller is enabled and caching both instruction and data type fetches after reset. it is possible to have these states for the cache: dfcc dfcic dfcda description 0 0 0 cache is on for both instruction and data. 0 0 1 cache is on for instruction and off for data. 0 1 0 cache is off for instruction and on for data. 0 1 1 cache is off for both instruction and data. 1 x x cache is off. address: f000_3000h base + ch offset = f000_300ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 esfc w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r dfcs efds dfcc dfcic dfcda 0 arb 0 w cfcc reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mcm_placr field descriptions field description 31C17 reserved this field is reserved. this read-only field is reserved and always has the value 0. 16 esfc enable stalling flash controller this field is used to enable stalling flash controller when flash is busy. 0 disable stalling flash controller when flash is busy. 1 enable stalling flash controller when flash is busy. table continues on the next page... memory map/register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 262 freescale semiconductor, inc.
mcm_placr field descriptions (continued) field description 15 dfcs disable flash controller speculation this field is used to disable flash controller speculation. 0 enable flash controller speculation. 1 disable flash controller speculation. 14 efds enable flash data speculation this field is used to enable flash data speculation. 0 disable flash data speculation. 1 enable flash data speculation. 13 dfcc disable flash controller cache this field is used to disable flash controller cache. 0 enable flash controller cache. 1 disable flash controller cache. 12 dfcic disable flash controller instruction caching this field is used to disable flash controller instruction caching. 0 enable flash controller instruction caching. 1 disable flash controller instruction caching. 11 dfcda disable flash controller data caching this field is used to disable flash controller data caching. 0 enable flash controller data caching 1 disable flash controller data caching. 10 cfcc clear flash controller cache writing a 1 to this field clears the cache. writing a 0 to this field is ignored. this field always reads as 0. 9 arb arbitration select 0 fixed-priority arbitration for the crossbar masters 1 round-robin arbitration for the crossbar masters 8C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. chapter 18 miscellaneous control module (mcm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 263
18.2.4 compute operation control register (mcm_cpo) this register controls the compute operation. address: f000_3000h base + 40h offset = f000_3040h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 cpowoi cpoack cporeq w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mcm_cpo field descriptions field description 31C3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 cpowoi compute operation wakeup on interrupt 0 no effect. 1 when set, the cporeq is cleared on any interrupt or exception vector fetch. 1 cpoack compute operation acknowledge 0 compute operation entry has not completed or compute operation exit has completed. 1 compute operation entry has completed or compute operation exit has not completed. 0 cporeq compute operation request this bit is auto-cleared by vector fetching if cpowoi = 1. table continues on the next page... memory map/register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 264 freescale semiconductor, inc.
mcm_cpo field descriptions (continued) field description 0 request is cleared. 1 request compute operation. chapter 18 miscellaneous control module (mcm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 265
memory map/register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 266 freescale semiconductor, inc.
chapter 19 micro trace buffer (mtb) 19.1 introduction microcontrollers using the cortex-m0+ processor core include support for a coresight micro trace buffer to provide program trace capabilities. the proper name for this function is the coresight micro trace buffer for the cortex-m0+ processor; in this document, it is simply abbreviated as the mtb. the simple program trace function creates instruction address change-of-flow data packets in a user-defined region of the system ram. accordingly, the system ram controller manages requests from two sources: ? amba-ahb reads and writes from the system bus ? program trace packet writes from the processor as part of the mtb functionality, there is a dwt (data watchpoint and trace) module that allows the user to define watchpoint addresses, or optionally, an address and data value, that when triggered, can be used to start or stop the program trace recording. this document details the functionality of both the mtb_ram and mtb_dwt capabilities. 19.1.1 overview a generic block diagram of the processor core and platform for this class of ultra low-end microcontrollers is shown as follows: kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 267
axbs cm0+ core platform s1 s2 m0 s0 fmc ld/st dbg nvic fetch cortex-m0+ core mtb port ahb bus m2 agu mul ram array 32 dec rn shft alu dma_4ch nvm array pram 32 rgpio pbridge bme 32 io port slave peripherals alt-master m3 figure 19-1. generic cortex-m0+ core platform block diagram as shown in the block diagram, the platform ram (pram) controller connects to two input buses: ? the crossbar slave port for system bus accesses ? a "private execution mtb port" from the core the logical paths from the crossbar master input ports to the pram controller are highlighted along with the private execution trace port from the processor core. the private mtb port signals the instruction address information needed for the 64-bit program trace packets written into the system ram. the pram controller output interfaces to the attached ram array. in this document, the pram controller is the mtb_ram controller. the following information is taken from the arm coresight micro trace buffer documentation. "the execution trace packet consists of a pair of 32-bit words that the mtb generates when it detects the processor pc value changes non-sequentially. a non-sequential pc change can occur during branch instructions or during exception entry. the processor can cause a trace packet to be generated for any instruction. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 268 freescale semiconductor, inc.
the following figure shows how the execution trace information is stored in memory as a sequence of packets. incrementing sram memory address nth destination address nth source address s a 31 0 1 2nd destination address 2nd source address s a 31 0 1 1st destination address 1st source address s a atom bit start bit odd word address even word address odd word address even word address figure 19-2. mtb execution trace storage format the first, lower addressed, word contains the source of the branch, the address it branched from. the value stored only records bits[31:1] of the source address, because thumb instructions are at least halfword aligned. the least significant bit of the value is the a-bit. the a-bit indicates the atomic state of the processor at the time of the branch, and can differentiate whether the branch originated from an instruction in a program, an exception, or a pc update in debug state. when it is zero the branch originated from an instruction, when it is one the branch originated from an exception or pc update in debug state. this word is always stored at an even word location. the second, higher addressed word contains the destination of the branch, the address it branched to. the value stored only records bits[31:1] of the branch address. the least significant bit of the value is the s-bit. the s-bit indicates where the trace started. an s- bit value of 1 indicates where the first packet after the trace started and a value of 0 is used for other packets. because it is possible to start and stop tracing multiple times in a trace session, the memory might contain several packets with the s-bit set to 1. this word is always stored in the next higher word in memory, an odd word address. when the a-bit is set to 1, the source address field contains the architecturally-preferred return address for the exception. for example, if an exception was caused by an svc instruction, then the source address field contains the address of the following instruction. this is different from the case where the a-bit is set to 0. in this case, the source address contains the address of the branch instruction. for an exception return operation, two packets are generated: ? the first packet has the: ? source address field set to the address of the instruction that causes the exception return, bx or pop. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 269
? destination address field set to bits[31:1] of the exc_return value. see the arm v6-m architecture reference manual. ? the a-bit set to 0. ? the second packet has the: ? source address field set to bits[31:1] of the exc_return value. ? destination address field set to the address of the instruction where execution commences. ? a-bit set to 1." given the recorded change-of-flow trace packets in system ram and the memory image of the application, a debugger can read out the data and create an instruction-by- instruction program trace. in keeping with the low area and power implementation cost design targets, the mtb trace format is less efficient than other coresight trace modules, for example, the etm (embedded trace macrocell). since each branch packet is 8 bytes in size, a 1 kb block of system ram can contain 128 branches. using the dhrystone 2.1 benchmark's dynamic runtime as an example, this corresponds to about 875 instructions per kb of trace ram, or with a zero wait state memory, this corresponds to approximately 1600 processor cycles per kb. this metric is obviously very sensitive to the runtime characteristics of the user code. the mtb_dwt function (not shown in the core platform block diagram) monitors the processor address and data buses so that configurable watchpoints can be detected to trigger the appropriate response in the mtb recording. 19.1.2 features the key features of the mtb_ram and mtb_dwt include: ? memory controller for system ram and micro trace buffer for program trace packets ? read/write capabilities for system ram accesses, write-only for program trace packets ? supports zero wait state response to system bus accesses when no trace data is being written ? can buffer two ahb address phases and one data write for system ram accesses ? supports 64-bit program trace packets including source and destination instruction addresses ? program trace information in ram available to mcu's application code or external debugger ? program trace watchpoint configuration accessible by mcu's application code or debugger ? location and size of ram trace buffer is configured by software introduction kl04 sub-family reference manual, rev. 3.1, november 2012 270 freescale semiconductor, inc.
? two dwt comparators (addresses or address + data) provide programmable start/ stop recording ? coresight compliant debug functionality 19.1.3 modes of operation the mtb_ram and mtb_dwt functions do not support any special modes of operation. the mtb_ram controller, as a memory-mapped device located on the platform's slave ahb system bus, responds based strictly on memory addresses for accesses to its attached ram array. the mtb private execution bus provides program trace packet write information to the ram controller. both the mtb_ram and mtb_dwt modules are memory-mapped so their programming models can be accessed. all functionality associated with the mtb_ram and mtb_dwt modules resides in the core platform's clock domain; this includes its connections with the ram array. 19.2 external signal description the mtb_ram and mtb_dwt modules do not directly support any external interfaces. the internal interfaces includes a standard ahb bus with a 32-bit datapath width from the appropriate crossbar slave port plus the private execution trace bus from the processor core. the signals in the private execution trace bus are detailed in the following table taken from the arm coresight micro trace buffer documentation. the signal direction is defined as viewed by the mtb_ram controller. table 19-1. private execution trace port from the core to mtb_ram signal direction description lockup input indicates the processor is in the lockup state. this signal is driven low for cycles when the processor is executing normally and driven high for every cycle the processor is waiting in the lockup state. this signal is valid on every cycle. iaeseq input indicates the next instruction address in execute, iaex, is sequential, that is non- branching. iaexen input iaex register enable. iaex[30:0] input registered address of the instruction in the execution stage, shifted right by one bit, that is, pc >> 1. atomic input indicates the processor is performing non-instruction related activities. edbgrq output request for the processor to enter the debug state, if enabled, and halt. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 271
in addition, there are two signals formed by the mtb_dwt module and driven to the mtb_ram controller: tstart (trace start) and tstop (trace stop). these signals can be configured using the trace watchpoints to define programmable addresses and data values to affect the program trace recording state. 19.3 memory map and register definition the mtb_ram and mtb_dwt modules each support a sparsely-populated 4 kb address space for their programming models. for each address space, there are a variety of control and configurable registers near the base address, followed by a large unused address space and finally a set of coresight registers to support dynamic determination of the debug configuration for the device. accesses to the programming model follow standard arm conventions. taken from the arm coresight micro trace buffer documentation, these are: ? do not attempt to access reserved or unused address locations. attempting to access these locations can result in unpredictable behavior. ? the behavior of the mtb is unpredictable if the registers with unknown reset values are not programmed prior to enabling trace. ? unless otherwise stated in the accompanying text: ? do not modify reserved register bits ? ignore reserved register bits on reads ? all register bits are reset to a logic 0 by a system or power-on reset ? use only word size, 32-bit, transactions to access all registers 19.3.1 mtb_ram memory map mtb memory map absolute address (hex) register name width (in bits) access reset value section/ page f000_0000 mtb position register (mtb_position) 32 r/w undefined 19.31.1/273 f000_0004 mtb master register (mtb_master) 32 r/w see section 19.31.2/275 f000_0008 mtb flow register (mtb_flow) 32 r/w undefined 19.31.3/277 f000_000c mtb base register (mtb_base) 32 r undefined 19.31.4/279 f000_0f00 integration mode control register (mtb_modectrl) 32 r 0000_0000h 19.31.5/279 f000_0fa0 claim tag set register (mtb_tagset) 32 r 0000_0000h 19.31.6/280 f000_0fa4 claim tag clear register (mtb_tagclear) 32 r 0000_0000h 19.31.7/280 f000_0fb0 lock access register (mtb_lockaccess) 32 r 0000_0000h 19.31.8/281 table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 272 freescale semiconductor, inc.
mtb memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page f000_0fb4 lock status register (mtb_lockstat) 32 r 0000_0000h 19.31.9/281 f000_0fb8 authentication status register (mtb_authstat) 32 r 0000_0000h 19.31.10/ 282 f000_0fbc device architecture register (mtb_devicearch) 32 r 4770_0a31h 19.31.11/ 283 f000_0fc8 device configuration register (mtb_devicecfg) 32 r 0000_0000h 19.31.12/ 283 f000_0fcc device type identifier register (mtb_devicetypid) 32 r 0000_0031h 19.31.13/ 284 f000_0fd0 peripheral id register (mtb_periphid4) 32 r see section 19.31.14/ 284 f000_0fd4 peripheral id register (mtb_periphid5) 32 r see section 19.31.14/ 284 f000_0fd8 peripheral id register (mtb_periphid6) 32 r see section 19.31.14/ 284 f000_0fdc peripheral id register (mtb_periphid7) 32 r see section 19.31.14/ 284 f000_0fe0 peripheral id register (mtb_periphid0) 32 r see section 19.31.14/ 284 f000_0fe4 peripheral id register (mtb_periphid1) 32 r see section 19.31.14/ 284 f000_0fe8 peripheral id register (mtb_periphid2) 32 r see section 19.31.14/ 284 f000_0fec peripheral id register (mtb_periphid3) 32 r see section 19.31.14/ 284 f000_0ff0 component id register (mtb_compid0) 32 r see section 19.31.15/ 285 f000_0ff4 component id register (mtb_compid1) 32 r see section 19.31.15/ 285 f000_0ff8 component id register (mtb_compid2) 32 r see section 19.31.15/ 285 f000_0ffc component id register (mtb_compid3) 32 r see section 19.31.15/ 285 19.31.1 mtb position register (mtb_position) the mtb_position register is the trace write address pointer and wrap bit. this register can be modified by the explicit programming model writes. it is also automatically updated by the mtb hardware when trace packets are being recorded. the base address of the system ram in the memory map dictates special consideration for the placement of the mtb. consider the following guidelines: chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 273
for the standard configuration where the size of the mtb is 25% of the total ram capacity, it is recommended the mtb be based at the address defined by the mtb_base register. the read-only mtb_base register is defined by the expression (0x2000_0000 - (ram_size/4)). for this configuration, the mtb_position register is initialized to (mtb_base & 0x0000_7ff8). if the size of the mtb is more than 25% but less than or equal to 50% of the total ram capacity, it is recommended the mtb be based at address 0x2000_0000. in this configuration, the mtb_position register is initialized to (0x2000_0000 & 0x0000_7ff8) = 0x0000_00000. following these two suggested placements provides a full-featured circular memory buffer containing program trace packets. in the unlikely event an even larger trace buffer is required, a write-once capacity of 75% of the total ram capacity can be based at address 0x2000_0000. the mtb_position register is initialized to (0x2000_0000 & 0x0000_7ff8) = 0x0000_0000. however, this configuration cannot support operation as a circular queue and instead requires the use of the mtb_flow[watermark] capability to automatically disable tracing or halting the processor as the number of packet writes approach the buffer capacity. see the mtb_flow register description for more details. address: f000_0000h base + 0h offset = f000_0000h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r pointer w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r pointer wrap 0 w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* 0 0 * notes: x = undefined at reset. ? mtb_position field descriptions field description 31C3 pointer trace packet address pointer[28:0] trace packet address pointer. because a packet consists of two words, the pointer field is the address of the first word of a packet. this field contains bits[31:3] of the ram address where the next trace packet is written. therefore, it points to an unused location and is automatically incremented. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 274 freescale semiconductor, inc.
mtb_position field descriptions (continued) field description a debug agent can calculate the system memory map address for the current location in the mtb using the following "generic" equation: given mtb_size = 1 << (mtb_master[mask] + 4), systemaddress = mtb_base + (((mtb_position & 0xffff_fff8) + (mtb_size - (mtb_base & (mtb_size-1)))) & 0x0000_7ff8); for this device, a simpler expression also applies. see the following pseudo-code: if ((mtb_position >> 13) == 0x3) systemaddress = (0x1fff << 16) + (0x1 << 15) + (mtb_position & 0x7ff8); else systemaddress = (0x2000 << 16) + (0x0 << 15) + (mtb_position & 0x7ff8); note: the size of the ram is parameterized and the most significant bits of the pointer field are raz/wi. for these devices, position[31:15] == position[pointer[28:12]] are raz/wi. therefore, the active bits in this field are position[14:3] == position[pointer[11:0]]. 2 wrap this bit is set to 1 automatically when the pointer value wraps as determined by the mtb_master[mask] field in the master trace control register. a debug agent might use the wrap bit to determine whether the trace information above and below the pointer address is valid. 1C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 19.31.2 mtb master register (mtb_master) the mtb_master register contains the main program trace enable plus other trace controls. this register can be modified by the explicit programming model writes. mtb_master[en] and mtb_master[haltreq] fields are also automatically updated by the mtb hardware. before the mtb_master[en] or mtb_master[tstarten] bits are set to 1, software must initialize the mtb_position and mtb_flow registers. if the mtb_flow[watermark] field is used to stop tracing or to halt the processor, the mtb_master[mask] field must still be set to a value that prevents the mtb_position[pointer] field from wrapping before it reaches the mtb_flow[watermark] value. note the format of this mask field is different than the mtbdwt_maskn[mask]. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 275
address: f000_0000h base + 4h offset = f000_0004h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r en 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 haltreq rampriv sfrwpriv tstopen tstarten mask w reset 0 0 0 0 0 0 0 0 1 0 0 x* x* x* x* x* * notes: x = undefined at reset. ? mtb_master field descriptions field description 31 en main trace enable bit when this bit is 1, trace data is written into the ram memory location addressed by mtb_position[pointer]. the mtb_position[pointer] value auto increments after the trace data packet is written. the en bit can be automatically set to 0 using the mtb_flow[watermark] field and the mtb_flow[autostop] bit. the en bit is automatically set to 1 if the tstarten bit is 1 and the tstart signal is high. the en bit is automatically set to 0 if tstopen bit is 1 and the tstop signal is high. note: if the en bit is set to 0 because the mtb_flow[watermark] field is set, then it is not automatically set to 1 if the tstarten bit is 1 and the tstart input is high. in this case, tracing can only be restarted if the mtb_flow[watermark] or mtb_position[pointer] value is changed by software. 30C10 reserved this field is reserved. this read-only field is reserved and always has the value 0. 9 haltreq halt request bit this bit is connected to the halt request signal of the trace logic, edbgrq. when haltreq is set to 1, the edbfgrq is asserted if dbgen (invasive debug enable, one of the debug authentication interface signals) is also high. the haltreq bit can be automatically set to 1 using the mtb_flow[watermark] field. 8 rampriv ram privilege bit if this bit is 0, then user or privileged ahb read and write accesses to the ram are permitted. if this bit is 1, then only privileged ahb read and write accesses to the ram are permitted and user accesses are raz/wi. the hprot[1] signal determines if an access is a user or privileged mode reference. 7 sfrwpriv special function register write privilege bit if this bit is 0, then user or privileged ahb read and write accesses to the mtb_ram special function registers (programming model) are permitted. if this bit is 1, then only privileged write accesses are table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 276 freescale semiconductor, inc.
mtb_master field descriptions (continued) field description permitted; user write accesses are ignored. the hprot[1] signal determines if an access is user or privileged. note mtb_ram sfr read access are not controlled by this bit and are always permitted. 6 tstopen trace stop input enable if this bit is 1 and the tstop signal is high, then the en bit is set to 0. if a trace packet is being written to memory, the write is completed before tracing is stopped. 5 tstarten trace start input enable if this bit is 1 and the tstart signal is high, then the en bit is set to 1. tracing continues until a stop condition occurs. 4C0 mask mask this value determines the maximum size of the trace buffer in ram. it specifies the most-significant bit of the mtb_position[pointer] field that can be updated by automatic increment. if the trace tries to advance past this power of two, the mtb_position[wrap] bit is set to 1, the mtb_position[mask +3:3] == mtb_position[pointer[mask:0]] bits are set to zero, and the mtb_position[14:mask+3] == mtb_position[pointer[11:mask+1]] bits remain unchanged. this field causes the trace packet information to be stored in a circular buffer of size 2^[mask+4] bytes, that can be positioned in memory at multiples of this size. as detailed in the mtb_position description, typical "upper limits" for the mtb size are ram_size/4 or ram_size/2. values greater than the maximum have the same effect as the maximum. 19.31.3 mtb flow register (mtb_flow) the mtb_flow register contains the watermark address and the autostop/autohalt control bits. if tracing is stopped using the watermark autostop feature, it cannot be restarted until software clears the watermark autostop. this can be achieved in one of the following ways: ? changing the mtb_position[pointer] field value to point to the beginning of the trace buffer, or ? setting mtb_flow[autostop] = 0. a debug agent can use the mtb_flow[autostop] bit to fill the trace buffer once only without halting the processor. a debug agent can use the mtb_flow[autohalt] bit to fill the trace buffer once before causing the cortex-m0+ processor to enter the debug state. to enter debug state, the cortex-m0+ processor might have to perform additional branch type operations. therefore, the mtb_flow[watermark] field must be set below the final entry in the trace buffer region. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 277
address: f000_0000h base + 8h offset = f000_0008h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r watermark w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r watermark 0 autohalt autostop w reset x* x* x* x* x* x* x* x* x* x* x* x* x* 0 x* x* * notes: x = undefined at reset. ? mtb_flow field descriptions field description 31C3 watermark watermark[28:0] this field contains an address in the same format as the mtb_position[pointer] field. when the mtb_position[pointer] matches the watermark field value, actions defined by the autohalt and autostop bits are performed. 2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 autohalt if this bit is 1 and watermark is equal to mtb_position[pointer], then the mtb_master[haltreq] bit is automatically set to 1. if the dbgen signal is high, the mtb asserts this halt request to the cortex-m0+ processor by asserting the edbgrq signal. 0 autostop if this bit is 1 and watermark is equal to mtb_position[pointer], then the mtb_master[en] bit is automatically set to 0. this stops tracing. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 278 freescale semiconductor, inc.
19.31.4 mtb base register (mtb_base) the read-only mtb_base register indicates where the ram is located in the system memory map. this register is provided to enable auto discovery of the mtb ram location, by a debug agent and is defined by a hardware design parameter. for this device, the base address is defined by the expression: mtb_base[baseaddr] = 0x2000_0000 - (ram_size/4) address: f000_0000h base + ch offset = f000_000ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r baseaddr w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: x = undefined at reset. ? mtb_base field descriptions field description 31C0 baseaddr this value is defined with a hardwired signal and the expression: 0x2000_0000 - (ram_size/4). for example, if the total ram capacity is 16 kb, this field is 0x1fff_f000. 19.31.5 integration mode control register (mtb_modectrl) this register enables the device to switch from a functional mode, or default behavior, into integration mode. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + f00h offset = f000_0f00h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r modectrl w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtb_modectrl field descriptions field description 31C0 modectrl hardwired to 0x0000_0000 chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 279
19.31.6 claim tag set register (mtb_tagset) the claim tag set register returns the number of bits that can be set on a read, and enables individual bits to be set on a write. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + fa0h offset = f000_0fa0h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r tagset w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtb_tagset field descriptions field description 31C0 tagset hardwired to 0x0000_0000 19.31.7 claim tag clear register (mtb_tagclear) the read/write claim tag clear register is used to read the claim status on debug resources. a read indicates the claim tag status. writing 1 to a specific bit clears the corresponding claim tag to 0. it is hardwired to specific values used during the auto- discovery process by an external debug agent. address: f000_0000h base + fa4h offset = f000_0fa4h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r tagclear w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtb_tagclear field descriptions field description 31C0 tagclear hardwired to 0x0000_0000 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 280 freescale semiconductor, inc.
19.31.8 lock access register (mtb_lockaccess) the lock access register enables a write access to component registers. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + fb0h offset = f000_0fb0h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r lockaccess w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtb_lockaccess field descriptions field description 31C0 lockaccess hardwired to 0x0000_0000 19.31.9 lock status register (mtb_lockstat) the lock status register indicates the status of the lock control mechanism. this register is used in conjunction with the lock access register. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + fb4h offset = f000_0fb4h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r lockstat w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtb_lockstat field descriptions field description 31C0 lockstat hardwired to 0x0000_0000 chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 281
19.31.10 authentication status register (mtb_authstat) the authentication status register reports the required security level and current status of the security enable bit pairs. where functionality changes on a given security level, this change must be reported in this register. it is connected to specific signals used during the auto-discovery process by an external debug agent. mtb_authstat[3:2] indicates if nonsecure, noninvasive debug is enabled or disabled, while mtb_authstat[1:0] indicates the enabled/disabled state of nonsecure, invasive debug. for both 2-bit fields, 0b10 indicates the functionality is disabled and 0b11 indicates it is enabled. address: f000_0000h base + fb8h offset = f000_0fb8h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 1 bit2 1 bit0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtb_authstat field descriptions field description 31C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 reserved this read-only field is reserved and always has the value 1. 2 bit2 connected to niden or dbgen signal. 1 reserved this read-only field is reserved and always has the value 1. 0 bit0 connected to dbgen. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 282 freescale semiconductor, inc.
19.31.11 device architecture register (mtb_devicearch) this register indicates the device architecture. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + fbch offset = f000_0fbch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r devicearch w reset 0 1 0 0 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 mtb_devicearch field descriptions field description 31C0 devicearch hardwired to 0x4770_0a31. 19.31.12 device configuration register (mtb_devicecfg) this register indicates the device configuration. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + fc8h offset = f000_0fc8h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r devicecfg w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtb_devicecfg field descriptions field description 31C0 devicecfg hardwired to 0x0000_0000. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 283
19.31.13 device type identifier register (mtb_devicetypid) this register indicates the device type id. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + fcch offset = f000_0fcch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r devicetypid w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 mtb_devicetypid field descriptions field description 31C0 devicetypid hardwired to 0x0000_0031. 19.31.14 peripheral id register (mtb_periphid n ) these registers indicate the peripheral ids. they are hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + fd0h offset + (4d i), where i=0d to 7d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r periphid w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: see field descriptions for the reset values.x = undefined at reset. ? mtb_periphid n field descriptions field description 31C0 periphid peripheral id4 is hardwired to 0x0000_0004; id0 to 0x0000_0032; id1 to 0x0000_00b9; id2 to 0x0000_000b; and all the others to 0x0000_0000. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 284 freescale semiconductor, inc.
19.31.15 component id register (mtb_compid n ) these registers indicate the component ids. they are hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_0000h base + ff0h offset + (4d i), where i=0d to 3d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r compid w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: see field descriptions for the reset values.x = undefined at reset. ? mtb_compid n field descriptions field description 31C0 compid component id component id0 is hardwired to 0x0000_000d; id1 to 0x0000_0090; id2 to 0x0000_0005; id3 to 0x0000_00b1. 19.3.2 mtb_dwt memory map the mtb_dwt programming model supports a very simplified subset of the v7m debug architecture and follows the standard arm dwt definition. mtbdwt memory map absolute address (hex) register name width (in bits) access reset value section/ page f000_1000 mtb dwt control register (mtbdwt_ctrl) 32 r 2f00_0000h 19.32.1/286 f000_1020 mtb_dwt comparator register (mtbdwt_comp0) 32 r/w 0000_0000h 19.32.2/287 f000_1024 mtb_dwt comparator mask register (mtbdwt_mask0) 32 r/w 0000_0000h 19.32.3/288 f000_1028 mtb_dwt comparator function register 0 (mtbdwt_fct0) 32 r/w 0000_0000h 19.32.4/289 f000_1030 mtb_dwt comparator register (mtbdwt_comp1) 32 r/w 0000_0000h 19.32.2/287 f000_1034 mtb_dwt comparator mask register (mtbdwt_mask1) 32 r/w 0000_0000h 19.32.3/288 f000_1038 mtb_dwt comparator function register 1 (mtbdwt_fct1) 32 r/w 0000_0000h 19.32.5/291 f000_1200 mtb_dwt trace buffer control register (mtbdwt_tbctrl) 32 r/w 2000_0000h 19.32.6/292 f000_1fc8 device configuration register (mtbdwt_devicecfg) 32 r 0000_0000h 19.32.7/294 table continues on the next page... chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 285
mtbdwt memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page f000_1fcc device type identifier register (mtbdwt_devicetypid) 32 r 0000_0004h 19.32.8/294 f000_1fd0 peripheral id register (mtbdwt_periphid4) 32 r see section 19.32.9/295 f000_1fd4 peripheral id register (mtbdwt_periphid5) 32 r see section 19.32.9/295 f000_1fd8 peripheral id register (mtbdwt_periphid6) 32 r see section 19.32.9/295 f000_1fdc peripheral id register (mtbdwt_periphid7) 32 r see section 19.32.9/295 f000_1fe0 peripheral id register (mtbdwt_periphid0) 32 r see section 19.32.9/295 f000_1fe4 peripheral id register (mtbdwt_periphid1) 32 r see section 19.32.9/295 f000_1fe8 peripheral id register (mtbdwt_periphid2) 32 r see section 19.32.9/295 f000_1fec peripheral id register (mtbdwt_periphid3) 32 r see section 19.32.9/295 f000_1ff0 component id register (mtbdwt_compid0) 32 r see section 19.32.10/ 295 f000_1ff4 component id register (mtbdwt_compid1) 32 r see section 19.32.10/ 295 f000_1ff8 component id register (mtbdwt_compid2) 32 r see section 19.32.10/ 295 f000_1ffc component id register (mtbdwt_compid3) 32 r see section 19.32.10/ 295 19.32.1 mtb dwt control register (mtbdwt_ctrl) the mtbdwt_ctrl register provides read-only information on the watchpoint configuration for the mtb_dwt. address: f000_1000h base + 0h offset = f000_1000h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r numcmp dwtcfgctrl w reset 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtbdwt_ctrl field descriptions field description 31C28 numcmp number of comparators the mtb_dwt implements two comparators. 27C0 dwtcfgctrl dwt configuration controls this field is hardwired to 0xf00_0000, disabling all the remaining dwt functionality. the specific fields and their state are: mtbdwt_ctrl[27] = notrcpkt = 1, trace sample and exception trace is not supported table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 286 freescale semiconductor, inc.
mtbdwt_ctrl field descriptions (continued) field description mtbdwt_ctrl[26] = noexttrig = 1, external match signals are not supported mtbdwt_ctrl[25] = nocyccnt = 1, cycle counter is not supported mtbdwt_ctrl[24] = noprfcnt = 1, profiling counters are not supported mtbdwt_ctrl[22] = cycebtena = 0, no postcnt underflow packets generated mtbdwt_ctrl[21] = foldevtena = 0, no folded instruction counter overflow events mtbdwt_ctrl[20] = lsuevtena = 0, no lsu counter overflow events mtbdwt_ctrl[19] = sleepevtena = 0, no sleep counter overflow events mtbdwt_ctrl[18] = excevtena = 0, no exception overhead counter events mtbdwt_ctrl[17] = cpievtena = 0, no cpi counter overflow events mtbdwt_ctrl[16] = exctrcena = 0, generation of exception trace disabled mtbdwt_ctrl[12] = pcsamplena = 0, no periodic pc sample packets generated mtbdwt_ctrl[11:10] = synctap = 0, no synchronization packets mtbdwt_ctrl[9] = cyctap = 0, cycle counter is not supported mtbdwt_ctrl[8:5] = postinit = 0, cycle counter is not supported mtbdwt_ctrl[4:1] = postpreset = 0, cycle counter is not supported mtbdwt_ctrl[0] = cyccntena = 0, cycle counter is not supported 19.32.2 mtb_dwt comparator register (mtbdwt_comp n ) the mtbdwt_compn registers provide the reference value for comparator n. address: f000_1000h base + 20h offset + (16d i), where i=0d to 1d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r comp w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtbdwt_comp n field descriptions field description 31C0 comp reference value for comparison if mtbdwt_comp0 is used for a data value comparator and the access size is byte or halfword, the data value must be replicated across all appropriate byte lanes of this register. for example, if the data is a byte-sized "x" value, then comp[31:24] = comp[23:16] = comp[15:8] = comp[7:0] = "x". likewise, if the data is a halfword-size "y" value, then comp[31:16] = comp[15:0] = "y". chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 287
19.32.3 mtb_dwt comparator mask register (mtbdwt_mask n ) the mtbdwt_maskn registers define the size of the ignore mask applied to the reference address for address range matching by comparator n. note the format of this mask field is different than the mtb_master[mask]. address: f000_1000h base + 24h offset + (16d i), where i=0d to 1d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 mask w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtbdwt_mask n field descriptions field description 31C5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4C0 mask mask the value of the ignore mask, 0-31 bits, is applied to address range matching. mask = 0 is used to include all bits of the address in the comparison, except if mask = 0 and the comparator is configured to watch instruction fetch addresses, address bit [0] is ignored by the hardware since all fetches must be at least halfword aligned. for mask != 0 and regardless of watch type, address bits [x-1:0] are ignored in the address comparison. using a mask means the comparator matches on a range of addresses, defined by the unmasked most significant bits of the address, bits [31:x]. the maximum mask value is 24, producing a 16 mbyte mask. an attempted write of a mask value > 24 is limited by the mtbdwt hardware to 24. if mtbdwt_comp0 is used as a data value comparator, then mtbdwt_mask0 should be programmed to zero. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 288 freescale semiconductor, inc.
19.32.4 mtb_dwt comparator function register 0 (mtbdwt_fct0) the mtbdwt_fctn registers control the operation of comparator n. address: f000_1000h base + 28h offset = f000_1028h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 matched 0 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r datavaddr0 datavsize 0 datavmatch 0 function w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtbdwt_fct0 field descriptions field description 31C25 reserved this field is reserved. this read-only field is reserved and always has the value 0. 24 matched comparator match if this read-only flag is asserted, it indicates the operation defined by the function field occurred since the last read of the register. reading the register clears this bit. table continues on the next page... chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 289
mtbdwt_fct0 field descriptions (continued) field description 0 no match. 1 match occurred. 23C20 reserved this field is reserved. this read-only field is reserved and always has the value 0. 19C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C12 datavaddr0 data value address 0 since the mtb_dwt implements two comparators, the datavaddr0 field is restricted to values {0,1}. when the datavmatch bit is asserted, this field defines the comparator number to use for linked address comparison. if mtbdwt_comp0 is used as a data watchpoint and mtbdwt_comp1 as an address watchpoint, datavaddr0 must be set. 11C10 datavsize data value size for data value matching, this field defines the size of the required data comparison. 00 byte. 01 halfword. 10 word. 11 reserved. any attempts to use this value results in unpredictable behavior. 9 reserved this field is reserved. this read-only field is reserved and always has the value 0. 8 datavmatch data value match the assertion of this bit enables data value comparison. for this implementation, mtbdwt_comp0 supports address or data value comparisons; mtbdwt_comp1 only supports address comparisons. 0 perform address comparison. 1 perform data value comparison. 7C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3C0 function function selects the action taken on a comparator match. if mtbdwt_comp0 is used for a data value and mtbdwt_comp1 for an address value, then mtbdwt_fct1[function] must be set to zero. for this configuration, mtbdwt_mask1 can be set to a non-zero value, so the combined comparators match on a range of addresses. 0000 disabled. 0100 instruction fetch. 0101 data operand read. 0110 data operand write. 0111 data operand (read + write). others reserved. any attempts to use this value results in unpredictable behavior. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 290 freescale semiconductor, inc.
19.32.5 mtb_dwt comparator function register 1 (mtbdwt_fct1) the mtbdwt_fctn registers control the operation of comparator n. since the mtb_dwt only supports data value comparisons on comparator 0, there are several fields in the mtbdwt_fct1 register that are raz/wi (bits 12, 11:10, 8). address: f000_1000h base + 38h offset = f000_1038h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 matched 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 function w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtbdwt_fct1 field descriptions field description 31C25 reserved this field is reserved. this read-only field is reserved and always has the value 0. 24 matched comparator match if this read-only flag is asserted, it indicates the operation defined by the function field occurred since the last read of the register. reading the register clears this bit. table continues on the next page... chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 291
mtbdwt_fct1 field descriptions (continued) field description 0 no match. 1 match occurred. 23C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3C0 function function selects the action taken on a comparator match. if mtbdwt_comp0 is used for a data value and mtbdwt_comp1 for an address value, then mtbdwt_fct1[function] must be set to zero. for this configuration, mtbdwt_mask1 can be set to a non-zero value, so the combined comparators match on a range of addresses. 0000 disabled. 0100 instruction fetch. 0101 data operand read. 0110 data operand write. 0111 data operand (read + write). others reserved. any attempts to use this value results in unpredictable behavior. 19.32.6 mtb_dwt trace buffer control register (mtbdwt_tbctrl) the mtbdwt_tbctrl register defines how the watchpoint comparisons control the actual trace buffer operation. recall the mtb supports starting and stopping the program trace based on the watchpoint comparisons signaled via tstart and tstop. the watchpoint comparison signals are enabled in the mtb's control logic by setting the appropriate enable bits, mtb_master[tstarten, tstopen]. in the event of simultaneous assertion of both tstart and tstop, tstart takes priority. address: f000_1000h base + 200h offset = f000_1200h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r numcomp 0 w reset 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 292 freescale semiconductor, inc.
bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 acomp1 acomp0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtbdwt_tbctrl field descriptions field description 31C28 numcomp number of comparators this read-only field specifies the number of comparators in the mtb_dwt. this implementation includes two registers. 27C2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 acomp1 action based on comparator 1 match when the mtbdwt_fct1[matched] is set, it indicates mtbdwt_comp1 address compare has triggered and the trace buffer's recording state is changed. 0 trigger tstop based on the assertion of mtbdwt_fct1[matched]. 1 trigger tstart based on the assertion of mtbdwt_fct1[matched]. 0 acomp0 action based on comparator 0 match when the mtbdwt_fct0[matched] is set, it indicates mtbdwt_comp0 address compare has triggered and the trace buffer's recording state is changed. the assertion of mtbdwt_fct0[matched] is caused by the following conditions: ? address match in mtbdwt_comp0 when mtbdwt_fct0[datavmatch] = 0 ? data match in mtbdwt_comp0 when mtbdwt_fct0[datavmatch, datavaddr0] = {1,0} ? data match in mtbdwt_comp0 and address match in mtbdwt_comp1 when mtbdwt_fct0[datavmatch, datavaddr0] = {1,1} 0 trigger tstop based on the assertion of mtbdwt_fct0[matched]. 1 trigger tstart based on the assertion of mtbdwt_fct0[matched]. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 293
19.32.7 device configuration register (mtbdwt_devicecfg) this register indicates the device configuration. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_1000h base + fc8h offset = f000_1fc8h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r devicecfg w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 mtbdwt_devicecfg field descriptions field description 31C0 devicecfg hardwired to 0x0000_0000. 19.32.8 device type identifier register (mtbdwt_devicetypid) this register indicates the device type id. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_1000h base + fcch offset = f000_1fcch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r devicetypid w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 mtbdwt_devicetypid field descriptions field description 31C0 devicetypid hardwired to 0x0000_0004. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 294 freescale semiconductor, inc.
19.32.9 peripheral id register (mtbdwt_periphid n ) these registers indicate the peripheral ids. they are hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_1000h base + fd0h offset + (4d i), where i=0d to 7d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r periphid w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: see field descriptions for the reset values. x = undefined at reset. ? mtbdwt_periphid n field descriptions field description 31C0 periphid peripheral id1 is hardwired to 0x0000_00e0; id2 to 0x0000_0008; and all the others to 0x0000_0000. 19.32.10 component id register (mtbdwt_compid n ) these registers indicate the component ids. they are hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_1000h base + ff0h offset + (4d i), where i=0d to 3d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r compid w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: see field descriptions for the reset values.x = undefined at reset. ? mtbdwt_compid n field descriptions field description 31C0 compid component id component id0 is hardwired to 0x0000_000d; id1 to 0x0000_0090; id2 to 0x0000_0005; id3 to 0x0000_00b1. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 295
19.3.3 system rom memory map the system rom table registers are also mapped into a sparsely-populated 4 kb address space. for core configurations like that supported by cortex-m0+, arm recommends that a debugger identifies and connects to the debug components using the coresight debug infrastructure. arm recommends that a debugger follows the flow as shown in the following figure to discover the components in the coresight debug infrastructure. in this case a debugger reads the peripheral and component id registers for each coresight component in the coresight system. figure 19-56. coresight discovery process rom memory map absolute address (hex) register name width (in bits) access reset value section/ page f000_2000 entry (rom_entry0) 32 r see section 19.33.1/297 f000_2004 entry (rom_entry1) 32 r see section 19.33.1/297 f000_2008 entry (rom_entry2) 32 r see section 19.33.1/297 f000_200c end of table marker register (rom_tablemark) 32 r 0000_0000h 19.33.2/298 f000_2fcc system access register (rom_sysaccess) 32 r 0000_0001h 19.33.3/298 f000_2fd0 peripheral id register (rom_periphid4) 32 r see section 19.33.4/299 f000_2fd4 peripheral id register (rom_periphid5) 32 r see section 19.33.4/299 f000_2fd8 peripheral id register (rom_periphid6) 32 r see section 19.33.4/299 table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 296 freescale semiconductor, inc.
rom memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page f000_2fdc peripheral id register (rom_periphid7) 32 r see section 19.33.4/299 f000_2fe0 peripheral id register (rom_periphid0) 32 r see section 19.33.4/299 f000_2fe4 peripheral id register (rom_periphid1) 32 r see section 19.33.4/299 f000_2fe8 peripheral id register (rom_periphid2) 32 r see section 19.33.4/299 f000_2fec peripheral id register (rom_periphid3) 32 r see section 19.33.4/299 f000_2ff0 component id register (rom_compid0) 32 r see section 19.33.5/299 f000_2ff4 component id register (rom_compid1) 32 r see section 19.33.5/299 f000_2ff8 component id register (rom_compid2) 32 r see section 19.33.5/299 f000_2ffc component id register (rom_compid3) 32 r see section 19.33.5/299 19.33.1 entry (rom_entry n ) the system rom table begins with "n" relative 32-bit addresses, one for each debug component present in the device and terminating with an all-zero value signaling the end of the table at the "n+1"-th value. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_2000h base + 0h offset + (4d i), where i=0d to 2d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r entry w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: see field descriptions for reset values.x = undefined at reset. ? rom_entry n field descriptions field description 31C0 entry entry entry 0 (mtb) is hardwired to 0xffff_e003; entry 1 (mtbdwt) to 0xffff_f003; entry 2 (cm0+ rom table) to 0xf00f_d003. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 297
19.33.2 end of table marker register (rom_tablemark) this register indicates end of table marker. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_2000h base + ch offset = f000_200ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r mark w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 rom_tablemark field descriptions field description 31C0 mark hardwired to 0x0000_0000 19.33.3 system access register (rom_sysaccess) this register indicates system access. it is hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_2000h base + fcch offset = f000_2fcch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r sysaccess w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 rom_sysaccess field descriptions field description 31C0 sysaccess hardwired to 0x0000_0001 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 298 freescale semiconductor, inc.
19.33.4 peripheral id register (rom_periphid n ) these registers indicate the peripheral ids. they are hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_2000h base + fd0h offset + (4d i), where i=0d to 7d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r periphid w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: see field descriptions for reset values.x = undefined at reset. ? rom_periphid n field descriptions field description 31C0 periphid peripheral id1 is hardwired to 0x0000_00e0; id2 to 0x0000_0008; and all the others to 0x0000_0000. 19.33.5 component id register (rom_compid n ) these registers indicate the component ids. they are hardwired to specific values used during the auto-discovery process by an external debug agent. address: f000_2000h base + ff0h offset + (4d i), where i=0d to 3d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r compid w reset x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* x* * notes: see field descriptions for reset values.x = undefined at reset. ? rom_compid n field descriptions field description 31C0 compid component id component id0 is hardwired to 0x0000_000d; id1 to 0x0000_0010; id2 to 0x0000_0005; id3 to 0x0000_00b1. chapter 19 micro trace buffer (mtb) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 299
memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 300 freescale semiconductor, inc.
chapter 20 crossbar switch lite (axbs-lite) 20.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. this chapter provides information on the layout, configuration, and programming of the crossbar switch. the crossbar switch connects bus masters and bus slaves using a crossbar switch structure. this structure allows up to four bus masters to access different bus slaves simultaneously, while providing arbitration among the bus masters when they access the same slave. 20.1.1 features the crossbar switch includes these features: ? symmetric crossbar bus switch implementation ? allows concurrent accesses from different masters to different slaves ? 32-bit data bus ? operation at a 1-to-1 clock frequency with the bus masters ? programmable configuration for fixed-priority or round-robin slave port arbitration 20.2 memory map / register definition this crossbar switch is designed for minimal gate count. it, therefore, has no memory- mapped configuration registers. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 301
20.3 functional description 20.3.1 general operation when a master accesses the crossbar switch the access is immediately taken. if the targeted slave port of the access is available, then the access is immediately presented on the slave port. single-clock or zero-wait-state accesses are possible through the crossbar. if the targeted slave port of the access is busy or parked on a different master port, the requesting master simply sees wait states inserted until the targeted slave port can service the master's request. the latency in servicing the request depends on each master's priority level and the responding slave's access time. because the crossbar switch appears to be just another slave to the master device, the master device has no knowledge of whether it actually owns the slave port it is targeting. while the master does not have control of the slave port it is targeting, it simply waits. a master is given control of the targeted slave port only after a previous access to a different slave port completes, regardless of its priority on the newly targeted slave port. this prevents deadlock from occurring when: ? a higher priority master has: ? an outstanding request to one slave port that has a long response time and ? a pending access to a different slave port, and ? a lower priority master is also making a request to the same slave port as the pending access of the higher priority master. after the master has control of the slave port it is targeting, the master remains in control of the slave port until it relinquishes the slave port by running an idle cycle or by targeting a different slave port for its next access. the master can also lose control of the slave port if another higher-priority master makes a request to the slave port. the crossbar terminates all master idle transfers, as opposed to allowing the termination to come from one of the slave buses. additionally, when no master is requesting access to a slave port, the crossbar drives idle transfers onto the slave bus, even though a default master may be granted access to the slave port. when a slave bus is being idled by the crossbar, it remains parked with the last master to use the slave port. this is done to save the initial clock of arbitration delay that otherwise would be seen if the master had to arbitrate to gain control of the slave port. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 302 freescale semiconductor, inc.
20.3.2 arbitration the crossbar switch supports two arbitration algorithms: ? fixed priority ? round robin the selection of the global slave port arbitration is controlled by mcm_placr[arb]. for fixed priority, set arb to 0. for round robin, set arb to 1. this arbitration setting applies to all slave ports. 20.3.2.1 arbitration during undefined length bursts all lengths of burst accesses lock out arbitration until the last beat of the burst. 20.3.2.2 fixed-priority operation when operating in fixed-priority mode, each master is assigned a unique priority level with the highest numbered master having the highest priority (master 1 has lower priority than master 3). if two masters request access to the same slave port, the master with the highest priority gains control over the slave port. note in this arbitration mode, a higher-priority master can monopolize a slave port, preventing accesses from any lower- priority master to the port. when a master makes a request to a slave port, the slave port checks whether the new requesting master's priority level is higher than that of the master that currently has control over the slave port, unless the slave port is in a parked state. the slave port performs an arbitration check at every clock edge to ensure that the proper master, if any, has control of the slave port. the following table describes possible scenarios based on the requesting master port: chapter 20 crossbar switch lite (axbs-lite) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 303
table 20-1. how axbs grants control of a slave port to a master when then axbs grants control to the requesting master both of the following are true: ? the current master is not running a transfer. ? the new requesting master's priority level is higher than that of the current master. at the next clock edge the requesting master's priority level is lower than the current master. at the conclusion of one of the following cycles: ? an idle cycle ? a non-idle cycle to a location other than the current slave port 20.3.2.3 round-robin priority operation when operating in round-robin mode, each master is assigned a relative priority based on the master port number. this relative priority is compared to the master port number (id) of the last master to perform a transfer on the slave bus. the highest priority requesting master becomes owner of the slave bus at the next transfer boundary. priority is based on how far ahead the id of the requesting master is to the id of the last master. after granted access to a slave port, a master may perform as many transfers as desired to that port until another master makes a request to the same slave port. the next master in line is granted access to the slave port at the next transfer boundary, or possibly on the next clock cycle if the current master has no pending access request. as an example of arbitration in round-robin mode, assume the crossbar is implemented with master ports 0, 1, 4, and 5. if the last master of the slave port was master 1, and master 0, 4, and 5 make simultaneous requests, they are serviced in the order: 4 then 5 then 0. the round-robin arbitration mode generally provides a more fair allocation of the available slave-port bandwidth (compared to fixed priority) as the fixed master priority does not affect the master selection. 20.4 initialization/application information no initialization is required for the crossbar switch. see the axbs section of the configuration chapter for the reset state of the arbitration scheme. initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 304 freescale semiconductor, inc.
chapter 21 peripheral bridge (aips-lite) 21.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the peripheral bridge converts the crossbar switch interface to an interface that can access most of the slave peripherals on this chip. the peripheral bridge supports up to 128 peripherals, each with a 4k-byte address space. (not all peripheral slots might be used. see the chip configuration chapter and memory map chapter for details on slot assignment.) the bridge includes separate clock enable inputs for each of the slots to accommodate slower peripherals. 21.1.1 features key features of the peripheral bridge are: ? supports peripheral slots with 8-, 16-, and 32-bit datapath width ? dedicated clock enables for independently configurable peripherals allow each on- or off-platform peripheral to operate at any integer-divisible speed less than or equal to the system clock frequency. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 305
21.1.2 general operation the slave devices connected to the peripheral bridge are modules which contain a programming model of control and status registers. the system masters read and write these registers through the peripheral bridge. the peripheral bridge performs a bus protocol conversion of the master transactions and generates the following as inputs to the peripherals: ? module enables ? module addresses ? transfer attributes ? byte enables ? write data the peripheral bridge selects and captures read data from the peripheral interface and returns it to the crossbar switch. the register maps of the peripherals are located on 4-kb boundaries. each peripheral is allocated one or more 4-kb block(s) of the memory map. the aips-lite module uses the accessed peripheral's data width to perform proper data byte lane routing; bus decomposition (bus sizing) is performed when the access size is larger than the peripheral's data width. 21.2 functional description the peripheral bridge functions as a bus protocol translator between the crossbar switch and the slave peripheral bus. the peripheral bridge manages all transactions destined for the attached slave devices and generates select signals for modules on the peripheral bus by decoding accesses within the attached address space. by default, reads and writes on the crossbar side of the peripheral bridge take two data- phase cycles. on the ips side, accesses complete in one cycle. if wait states are inserted by the slave peripheral, access time will be extended accordingly. 21.2.1 access support all combinations of access size and peripheral data port width are supported. an access that is larger than the target peripheral's data width will be decomposed to multiple, smaller accesses. bus decomposition is terminated by a transfer error caused by an access to an empty register area. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 306 freescale semiconductor, inc.
chapter 22 direct memory access multiplexer (dmamux) 22.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. 22.1.1 overview the direct memory access multiplexer (dmamux) routes dma sources, called slots, to any of the 4 dma channels. this process is illustrated in the following figure. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 307
dma channel #0 source #1 source #2 source #3 always #1 dma channel #n always # y source # x trigger #1 trigger # z dma channel #1 dmamux figure 22-1. dmamux block diagram 22.1.2 features the dmamux module provides these features: ? 6353 peripheral slots and 6 always-on slots can be routed to 4 channels. ? 4 independently selectable dma channel routers. ? the first 2 channels additionally provide a trigger functionality. ? each channel router can be assigned to one of the 6353 possible peripheral dma slots or to one of the 6 always-on slots. 22.1.3 modes of operation the following operating modes are available: ? disabled mode introduction kl04 sub-family reference manual, rev. 3.1, november 2012 308 freescale semiconductor, inc.
in this mode, the dma channel is disabled. because disabling and enabling of dma channels is done primarily via the dma configuration registers, this mode is used mainly as the reset state for a dma channel in the dma channel mux. it may also be used to temporarily suspend a dma channel while reconfiguration of the system takes place, for example, changing the period of a dma trigger. ? normal mode in this mode, a dma source is routed directly to the specified dma channel. the operation of the dmamux in this mode is completely transparent to the system. ? periodic trigger mode in this mode, a dma source may only request a dma transfer, such as when a transmit buffer becomes empty or a receive buffer becomes full, periodically. configuration of the period is done in the registers of the periodic interrupt timer (pit). this mode is available only for channels 0C1. 22.2 external signal description the dmamux has no external pins. 22.3 memory map/register definition this section provides a detailed description of all memory-mapped registers in the dmamux. dmamux memory map absolute address (hex) register name width (in bits) access reset value section/ page 4002_1000 channel configuration register (dmamux0_chcfg0) 8 r/w 00h 22.3.1/309 4002_1001 channel configuration register (dmamux0_chcfg1) 8 r/w 00h 22.3.1/309 4002_1002 channel configuration register (dmamux0_chcfg2) 8 r/w 00h 22.3.1/309 4002_1003 channel configuration register (dmamux0_chcfg3) 8 r/w 00h 22.3.1/309 22.3.1 channel configuration register (dmamux x _chcfg n ) each of the dma channels can be independently enabled/disabled and associated with one of the dma slots (peripheral slots or always-on slots) in the system. chapter 22 direct memory access multiplexer (dmamux) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 309
note setting multiple chcfg registers with the same source value will result in unpredictable behavior. note before changing the trigger or source settings a dma channel must be disabled via the chcfgn[enbl] bit. address: 4002_1000h base + 0h offset + (1d i), where i=0d to 3d bit 0 1 2 3 4 5 6 7 read enbl trig source write reset 0 0 0 0 0 0 0 0 dmamux x _chcfg n field descriptions field description 0 enbl dma channel enable enables the dma channel. 0 dma channel is disabled. this mode is primarily used during configuration of the dma mux. the dma has separate channel enables/disables, which should be used to disable or re-configure a dma channel. 1 dma channel is enabled 1 trig dma channel trigger enable enables the periodic trigger capability for the triggered dma channel. 0 triggering is disabled. if triggering is disabled, and the enbl bit is set, the dma channel will simply route the specified source to the dma channel. (normal mode) 1 triggering is enabled. if triggering is enabled, and the enbl bit is set, the dmamux is in periodic trigger mode. 2C7 source dma channel source (slot) specifies which dma source, if any, is routed to a particular dma channel. see your device's chip configuration details for further details about the peripherals and their slot numbers. 22.4 functional description the primary purpose of the dmamux is to provide flexibility in the system's use of the available dma channels. as such, configuration of the dmamux is intended to be a static procedure done during execution of the system boot code. however, if the procedure outlined in enabling and configuring sources is followed, the configuration of the dmamux may be changed during the normal operation of the system. functionally, the dmamux channels may be divided into two classes: functional description kl04 sub-family reference manual, rev. 3.1, november 2012 310 freescale semiconductor, inc.
? channels which implement the normal routing functionality plus periodic triggering capability ? channels which implement only the normal routing functionality 22.4.1 dma channels with periodic triggering capability besides the normal routing functionality, the first 2 channels of the dmamux provide a special periodic triggering capability that can be used to provide an automatic mechanism to transmit bytes, frames, or packets at fixed intervals without the need for processor intervention. the trigger is generated by the periodic interrupt timer (pit); as such, the configuration of the periodic triggering interval is done via configuration registers in the pit. see the section on periodic interrupt timer for more information on this topic. note because of the dynamic nature of the system (due to dma channel priorities, bus arbitration, interrupt service routine lengths, etc.), the number of clock cycles between a trigger and the actual dma transfer cannot be guaranteed. dma channel #0 trigger #2 source #1 source #2 source #3 always #1 dma channel #3 always # y trigger #4 source # x trigger #1 dma channel #1 figure 22-12. dmamux triggered channels chapter 22 direct memory access multiplexer (dmamux) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 311
the dma channel triggering capability allows the system to schedule regular dma transfers, usually on the transmit side of certain peripherals, without the intervention of the processor. this trigger works by gating the request from the peripheral to the dma until a trigger event has been seen. this is illustrated in the following figure. dma request peripheral request trigger figure 22-13. dmamux channel triggering: normal operation after the dma request has been serviced, the peripheral will negate its request, effectively resetting the gating mechanism until the peripheral re-asserts its request and the next trigger event is seen. this means that if a trigger is seen, but the peripheral is not requesting a transfer, then that trigger will be ignored. this situation is illustrated in the following figure. dma request peripheral request trigger figure 22-14. dmamux channel triggering: ignored trigger this triggering capability may be used with any peripheral that supports dma transfers, and is most useful for two types of situations: ? periodically polling external devices on a particular bus as an example, the transmit side of an spi is assigned to a dma channel with a trigger, as described above. after it has been set up, the spi will request dma transfers, presumably from memory, as long as its transmit buffer is empty. by using a trigger on this channel, the spi transfers can be automatically performed every 5 s (as an example). on the receive side of the spi, the spi and dma can be configured to transfer receive data into memory, effectively implementing a method to periodically read data from external devices and transfer the results into memory without processor intervention. ? using the gpio ports to drive or sample waveforms functional description kl04 sub-family reference manual, rev. 3.1, november 2012 312 freescale semiconductor, inc.
by configuring the dma to transfer data to one or more gpio ports, it is possible to create complex waveforms using tabular data stored in on-chip memory. conversely, using the dma to periodically transfer data from one or more gpio ports, it is possible to sample complex waveforms and store the results in tabular form in on- chip memory. a more detailed description of the capability of each trigger, including resolution, range of values, and so on, may be found in the periodic interrupt timer section. 22.4.2 dma channels with no triggering capability the other channels of the dmamux provide the normal routing functionality as described in modes of operation . 22.4.3 always-enabled dma sources in addition to the peripherals that can be used as dma sources, there are 6 additional dma sources that are always enabled. unlike the peripheral dma sources, where the peripheral controls the flow of data during dma transfers, the sources that are always enabled provide no such "throttling" of the data transfers. these sources are most useful in the following cases: ? performing dma transfers to/from gpiomoving data from/to one or more gpio pins, either unthrottled (that is as fast as possible), or periodically (using the dma triggering capability). ? performing dma transfers from memory to memorymoving data from memory to memory, typically as fast as possible, sometimes with software activation. ? performing dma transfers from memory to the external bus, or vice-versasimilar to memory to memory transfers, this is typically done as quickly as possible. ? any dma transfer that requires software activationany dma transfer that should be explicitly started by software. in cases where software should initiate the start of a dma transfer, an always-enabled dma source can be used to provide maximum flexibility. when activating a dma channel via software, subsequent executions of the minor loop require that a new start event be sent. this can either be a new software activation, or a transfer request from the dma channel mux. the options for doing this are: ? transfer all data in a single minor loop. chapter 22 direct memory access multiplexer (dmamux) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 313
by configuring the dma to transfer all of the data in a single minor loop (that is, major loop counter = 1), no reactivation of the channel is necessary. the disadvantage to this option is the reduced granularity in determining the load that the dma transfer will impose on the system. for this option, the dma channel must be disabled in the dma channel mux. ? use explicit software reactivation. in this option, the dma is configured to transfer the data using both minor and major loops, but the processor is required to reactivate the channel by writing to the dma registers after every minor loop . for this option, the dma channel must be disabled in the dma channel mux. ? use an always-enabled dma source. in this option, the dma is configured to transfer the data using both minor and major loops, and the dma channel mux does the channel reactivation. for this option, the dma channel should be enabled and pointing to an "always enabled" source. note that the reactivation of the channel can be continuous (dma triggering is disabled) or can use the dma triggering capability. in this manner, it is possible to execute periodic transfers of packets of data from one source to another, without processor intervention. 22.5 initialization/application information this section provides instructions for initializing the dma channel mux. 22.5.1 reset the reset state of each individual bit is shown in memory map/register definition . in summary, after reset, all channels are disabled and must be explicitly enabled before use. 22.5.2 enabling and configuring sources to enable a source with periodic triggering: 1. determine with which dma channel the source will be associated. note that only the first 2 dma channels have periodic triggering capability. 2. clear the chcfg[enbl] and chcfg[trig] fields of the dma channel. initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 314 freescale semiconductor, inc.
3. ensure that the dma channel is properly configured in the dma. the dma channel may be enabled at this point. 4. configure the corresponding timer. 5. select the source to be routed to the dma channel. write to the corresponding chcfg register, ensuring that the chcfg[enbl] and chcfg[trig] fields are set. note the following is an example. see chip configuration section for the number of this device's dma channels that have triggering capability. to configure source #5 transmit for use with dma channel 2, with periodic triggering capability: 1. write 0x00 to chcfg2 (base address + 0x02). 2. configure channel 2 in the dma, including enabling the channel. 3. configure a timer for the desired trigger interval. 4. write 0xc5 to chcfg2 (base address + 0x02). the following code example illustrates steps 1 and 4 above: in file registers.h: #define dmamux_base_addr 0xfc084000/* example only ! */ /* following example assumes char is 8-bits */ volatile unsigned char *chconfig0 = (volatile unsigned char *) (dmamux_base_addr+0x0000); volatile unsigned char *chconfig1 = (volatile unsigned char *) (dmamux_base_addr+0x0001); volatile unsigned char *chconfig2 = (volatile unsigned char *) (dmamux_base_addr+0x0002); volatile unsigned char *chconfig3 = (volatile unsigned char *) (dmamux_base_addr+0x0003); volatile unsigned char *chconfig4 = (volatile unsigned char *) (dmamux_base_addr+0x0004); volatile unsigned char *chconfig5 = (volatile unsigned char *) (dmamux_base_addr+0x0005); volatile unsigned char *chconfig6 = (volatile unsigned char *) (dmamux_base_addr+0x0006); volatile unsigned char *chconfig7 = (volatile unsigned char *) (dmamux_base_addr+0x0007); volatile unsigned char *chconfig8 = (volatile unsigned char *) (dmamux_base_addr+0x0008); volatile unsigned char *chconfig9 = (volatile unsigned char *) (dmamux_base_addr+0x0009); volatile unsigned char *chconfig10= (volatile unsigned char *) (dmamux_base_addr+0x000a); volatile unsigned char *chconfig11= (volatile unsigned char *) (dmamux_base_addr+0x000b); volatile unsigned char *chconfig12= (volatile unsigned char *) (dmamux_base_addr+0x000c); volatile unsigned char *chconfig13= (volatile unsigned char *) (dmamux_base_addr+0x000d); volatile unsigned char *chconfig14= (volatile unsigned char *) (dmamux_base_addr+0x000e); volatile unsigned char *chconfig15= (volatile unsigned char *) (dmamux_base_addr+0x000f); in file main.c: #include "registers.h" : : *chconfig2 = 0x00; *chconfig2 = 0xc5; to enable a source without periodic triggering: 1. determine with which dma channel the source will be associated. note that only the first 2 dma channels have periodic triggering capability. 2. clear the chcfg[enbl] and chcfg[trig] fields of the dma channel. chapter 22 direct memory access multiplexer (dmamux) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 315
3. ensure that the dma channel is properly configured in the dma. the dma channel may be enabled at this point. 4. select the source to be routed to the dma channel. write to the corresponding chcfg register, ensuring that chcfg[enbl] is set while chcfg[trig] is cleared. note the following is an example. see chip configuration section for the number of this device's dma channels that have triggering capability. to configure source #5 transmit for use with dma channel 2, with no periodic triggering capability: 1. write 0x00 to chcfg2 (base address + 0x02). 2. configure channel 2 in the dma, including enabling the channel. 3. write 0x85 to chcfg2 (base address + 0x02). the following code example illustrates steps 1 and 3 above: in file registers.h: #define dmamux_base_addr 0xfc084000/* example only ! */ /* following example assumes char is 8-bits */ volatile unsigned char *chconfig0 = (volatile unsigned char *) (dmamux_base_addr+0x0000); volatile unsigned char *chconfig1 = (volatile unsigned char *) (dmamux_base_addr+0x0001); volatile unsigned char *chconfig2 = (volatile unsigned char *) (dmamux_base_addr+0x0002); volatile unsigned char *chconfig3 = (volatile unsigned char *) (dmamux_base_addr+0x0003); volatile unsigned char *chconfig4 = (volatile unsigned char *) (dmamux_base_addr+0x0004); volatile unsigned char *chconfig5 = (volatile unsigned char *) (dmamux_base_addr+0x0005); volatile unsigned char *chconfig6 = (volatile unsigned char *) (dmamux_base_addr+0x0006); volatile unsigned char *chconfig7 = (volatile unsigned char *) (dmamux_base_addr+0x0007); volatile unsigned char *chconfig8 = (volatile unsigned char *) (dmamux_base_addr+0x0008); volatile unsigned char *chconfig9 = (volatile unsigned char *) (dmamux_base_addr+0x0009); volatile unsigned char *chconfig10= (volatile unsigned char *) (dmamux_base_addr+0x000a); volatile unsigned char *chconfig11= (volatile unsigned char *) (dmamux_base_addr+0x000b); volatile unsigned char *chconfig12= (volatile unsigned char *) (dmamux_base_addr+0x000c); volatile unsigned char *chconfig13= (volatile unsigned char *) (dmamux_base_addr+0x000d); volatile unsigned char *chconfig14= (volatile unsigned char *) (dmamux_base_addr+0x000e); volatile unsigned char *chconfig15= (volatile unsigned char *) (dmamux_base_addr+0x000f); in file main.c: #include "registers.h" : : *chconfig2 = 0x00; *chconfig2 = 0x85; to disable a source: a particular dma source may be disabled by not writing the corresponding source value into any of the chcfg registers. additionally, some module-specific configuration may be necessary. see the appropriate section for more details. to switch the source of a dma channel: initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 316 freescale semiconductor, inc.
1. disable the dma channel in the dma and re-configure the channel for the new source. 2. clear the chcfg[enbl] and chcfg[trig] bits of the dma channel. 3. select the source to be routed to the dma channel. write to the corresponding chcfg register, ensuring that the chcfg[enbl] and chcfg[trig] fields are set. to switch dma channel 8 from source #5 transmit to source #7 transmit: 1. in the dma configuration registers, disable dma channel 8 and reconfigure it to handle the transfers to peripheral slot 7. this example assumes channel 8 doesn't have triggering capability. 2. write 0x00 to chcfg8 (base address + 0x08). 3. write 0x87 to chcfg8 (base address + 0x08). (in this example, setting chcfg[trig] would have no effect, due to the assumption that channel 8 does not support the periodic triggering functionality). the following code example illustrates steps 2 and 3 above: in file registers.h: #define dmamux_base_addr 0xfc084000/* example only ! */ /* following example assumes char is 8-bits */ volatile unsigned char *chconfig0 = (volatile unsigned char *) (dmamux_base_addr+0x0000); volatile unsigned char *chconfig1 = (volatile unsigned char *) (dmamux_base_addr+0x0001); volatile unsigned char *chconfig2 = (volatile unsigned char *) (dmamux_base_addr+0x0002); volatile unsigned char *chconfig3 = (volatile unsigned char *) (dmamux_base_addr+0x0003); volatile unsigned char *chconfig4 = (volatile unsigned char *) (dmamux_base_addr+0x0004); volatile unsigned char *chconfig5 = (volatile unsigned char *) (dmamux_base_addr+0x0005); volatile unsigned char *chconfig6 = (volatile unsigned char *) (dmamux_base_addr+0x0006); volatile unsigned char *chconfig7 = (volatile unsigned char *) (dmamux_base_addr+0x0007); volatile unsigned char *chconfig8 = (volatile unsigned char *) (dmamux_base_addr+0x0008); volatile unsigned char *chconfig9 = (volatile unsigned char *) (dmamux_base_addr+0x0009); volatile unsigned char *chconfig10= (volatile unsigned char *) (dmamux_base_addr+0x000a); volatile unsigned char *chconfig11= (volatile unsigned char *) (dmamux_base_addr+0x000b); volatile unsigned char *chconfig12= (volatile unsigned char *) (dmamux_base_addr+0x000c); volatile unsigned char *chconfig13= (volatile unsigned char *) (dmamux_base_addr+0x000d); volatile unsigned char *chconfig14= (volatile unsigned char *) (dmamux_base_addr+0x000e); volatile unsigned char *chconfig15= (volatile unsigned char *) (dmamux_base_addr+0x000f); in file main.c: #include "registers.h" : : *chconfig8 = 0x00; *chconfig8 = 0x87; chapter 22 direct memory access multiplexer (dmamux) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 317
initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 318 freescale semiconductor, inc.
chapter 23 dma controller module 23.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. this chapter describes the direct memory access (dma) controller module. it provides an overview of the module and describes in detail its signals and programming model. the latter sections of this chapter describe operations, features, and supported data transfer modes in detail. note the designation n is used throughout this section to refer to registers or signals associated with one of the four identical dma channels: dma0, dma1, dma2, or dma3. 23.1.1 overview the dma controller module enables fast transfers of data, providing an efficient way to move blocks of data with minimal processor interaction. the dma module, shown in the following figure, has four channels that allow 8-bit, 16-bit, or 32-bit data transfers. each channel has a dedicated source address register (sar n ), destination address register (dar n ), status register (dsr n ), byte count register (bcr n ), and control register (dcr n ). collectively, the combined program-visible registers associated with each channel define a transfer control descriptor (tcd). all transfers are dual address, moving data from a source memory location to a destination memory location with the module operating as a 32-bit bus master connected to the system bus. the programming model is accessed through a 32-bit connection with the slave peripheral bus. dma data transfers may be explicitly initiated by software or by peripheral hardware requests. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 319
the following figure is a simplified block diagram of the 4-channel dma controller. sar0 dar0 dsr0 bcr0 dcr0 channel 0 sar1 dar1 dsr1 bcr1 dcr1 channel 1 sar2 dar2 dsr2 bcr2 dcr2 channel 2 sar3 dar3 dsr3 bcr3 dcr3 channel 3 dreq2 dack3 dreq0 dreq1 data path dreq3 addr + attr interrupts phase bus signals current master attributes write data bus read data bus system bus address system bus size sysbus interface mux sysbus interface registered addr dack2dack1dack0 slave peripheral bus channel requests channel enables channel attributes mux control arbitraton/ control data path control figure 23-1. 4-channel dma block diagram the terms peripheral request and dreq refer to a dma request from one of the on-chip peripherals or package pins. the dma provides hardware handshake signals: either a dma acknowledge (dack) or a done indicator back to the peripheral. 23.1.2 features the dma controller module features: ? four independently programmable dma controller channels ? dual-address transfers via 32-bit master connection to the system bus ? data transfers in 8-, 16-, or 32-bit blocks introduction kl04 sub-family reference manual, rev. 3.1, november 2012 320 freescale semiconductor, inc.
? continuous-mode or cycle-steal transfers from software or peripheral initiation ? automatic hardware acknowledge/done indicator from each channel ? independent source and destination address registers ? optional modulo addressing and automatic updates of source and destination addresses ? independent transfer sizes for source and destination ? optional auto-alignment feature for source or destination accesses ? optional automatic single or double channel linking ? programming model accessed via 32-bit slave peripheral bus ? channel arbitration on transfer boundaries using fixed priority scheme 23.2 dma transfer overview the dma module can move data within system memory (including memory and peripheral devices) with minimal processor intervention, greatly improving overall system performance. the dma module consists of four independent, functionally equivalent channels, so references to dma in this chapter apply to any of the channels. it is not possible to address all four channels at once. as soon as a channel has been initialized, it may be started by setting dcr n [start] or a properly-selected peripheral dma request, depending on the status of dcr n [erq]. the dma controller supports dual-address transfers using its bus master connection to the system bus. the dma channels support transfers up to 32 data bits in size and have the same memory map addressibility as the processor. ? dual-address transfersa dual-address transfer consists of a read followed by a write and is initiated by a request using the dcrn[start] bit or by a peripheral dma request. the read data is temporarily held in the dma channel hardware until the write operation. two types of single transfers occur: a read from a source address followed by a write to a destination address. see the following figure. chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 321
control and data write read dma memory/ peripheral memory/ peripheral control and data figure 23-2. dual-address transfer any operation involving a dma channel follows the same three steps: 1. channel initializationthe transfer control descriptor, contained in the channel registers, is loaded with address pointers, a byte-transfer count, and control information using accesses from the slave peripheral bus. 2. data transferthe dma accepts requests for data transfers. upon receipt of a request, it provides address and bus control for the transfers via its master connection to the system bus and temporary storage for the read data. the channel performs one or more source read and destination write data transfers. 3. channel terminationoccurs after the operation is finished successfully or due to an error. the channel indicates the operation status in the channel's dsr, described in the definitions of the dma status registers (dsrn) and byte count registers (bcrn). memory map and registers descriptions of each register and its bit assignments follow. modifying dma control registers during a transfer can result in undefined operation. the following table shows the mapping of dma controller registers. the dma programming model is accessed via the slave peripheral bus. the concatenation of the source and destination address registers, the status and byte count register, and the control register create a 128-bit transfer control descriptor (tcd) that defines the operation of each dma channel. 23.3 memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 322 freescale semiconductor, inc.
dma memory map absolute address (hex) register name width (in bits) access reset value section/ page 4000_8100 source address register (dma_sar0) 32 r/w 0000_0000h 23.3.1/323 4000_8104 destination address register (dma_dar0) 32 r/w 0000_0000h 23.3.2/324 4000_8108 dma status register / byte count register (dma_dsr_bcr0) 32 r/w 0000_0000h 23.3.3/325 4000_810c dma control register (dma_dcr0) 32 r/w 0000_0000h 23.3.4/327 4000_8110 source address register (dma_sar1) 32 r/w 0000_0000h 23.3.1/323 4000_8114 destination address register (dma_dar1) 32 r/w 0000_0000h 23.3.2/324 4000_8118 dma status register / byte count register (dma_dsr_bcr1) 32 r/w 0000_0000h 23.3.3/325 4000_811c dma control register (dma_dcr1) 32 r/w 0000_0000h 23.3.4/327 4000_8120 source address register (dma_sar2) 32 r/w 0000_0000h 23.3.1/323 4000_8124 destination address register (dma_dar2) 32 r/w 0000_0000h 23.3.2/324 4000_8128 dma status register / byte count register (dma_dsr_bcr2) 32 r/w 0000_0000h 23.3.3/325 4000_812c dma control register (dma_dcr2) 32 r/w 0000_0000h 23.3.4/327 4000_8130 source address register (dma_sar3) 32 r/w 0000_0000h 23.3.1/323 4000_8134 destination address register (dma_dar3) 32 r/w 0000_0000h 23.3.2/324 4000_8138 dma status register / byte count register (dma_dsr_bcr3) 32 r/w 0000_0000h 23.3.3/325 4000_813c dma control register (dma_dcr3) 32 r/w 0000_0000h 23.3.4/327 23.3.1 source address register (dma_sar n ) restriction for this register: ? only 32-bit writes are allowed. 16-bit and 8-bit writes result in a bus error. ? only four values are allowed to be written to bits 31-20 of this register. a write of any other value to these bits causes a configuration error when the channel starts to execute. for more information about the configuration error, see the description of the ce field of dsr. address: 4000_8000h base + 100h offset + (16d i), where i=0d to 3d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r sar w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 323
dma_sar n field descriptions field description 31C0 sar each sar contains the byte address used by the dma controller to read data. the sarn is typically aligned on a 0-modulo-ssize boundarythat is, on the natural alignment of the source data. restriction: bits 31-20 of this register must be written with one of only four allowed values. each of these four allowed values corresponds to a valid region of the device's memory map. the allowed values are: ? 0x000x_xxxx ? 0x1ffx_xxxx ? 0x200x_xxxx ? 0x400x_xxxx after being written with one of the allowed values, bits 31-20 read back as the written value. after being written with any other value, bits 31-20 read back as an indeterminate value. 23.3.2 destination address register (dma_dar n ) restriction for this register: ? only 32-bit writes are allowed. 16-bit and 8-bit writes result in a bus error. ? only four values are allowed to be written to bits 31-20 of this register. a write of any other value to these bits causes a configuration error when the channel starts to execute. for more information about the configuration error, see the description of the ce field of dsr. address: 4000_8000h base + 104h offset + (16d i), where i=0d to 3d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r dar w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 dma_dar n field descriptions field description 31C0 dar each dar contains the byte address used by the dma controller to write data. the darn is typically aligned on a 0-modulo-dsize boundarythat is, on the natural alignment of the destination data. restriction: bits 31-20 of this register must be written with one of only four allowed values. each of these four allowed values corresponds to a valid region of the device's memory map. the allowed values are: ? 0x000x_xxxx ? 0x1ffx_xxxx ? 0x200x_xxxx ? 0x400x_xxxx memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 324 freescale semiconductor, inc.
dma_dar n field descriptions (continued) field description after being written with one of the allowed values, bits 31-20 read back as the written value. after being written with any other value, bits 31-20 read back as an indeterminate value. 23.3.3 dma status register / byte count register (dma_dsr_bcr n ) dsr and bcr are two logical registers that occupy one 32-bit address. dsrn occupies bits 31C24, and bcrn occupies bits 23C0. dsrn contains flags indicating the channel status, and bcrn contains the number of bytes yet to be transferred for a given block. on the successful completion of the write transfer, bcrn decrements by 1, 2, or 4 for 8- bit, 16-bit, or 32-bit accesses, respectively. bcrn is cleared if a 1 is written to dsr[done]. in response to an event, the dma controller writes to the appropriate dsrn bit. only a write to dsrn[done] results in action. dsrn[done] is set when the block transfer is complete. when a transfer sequence is initiated and bcrn[bcr] is not a multiple of 4 or 2 when the dma is configured for 32-bit or 16-bit transfers, respectively, dsrn[ce] is set and no transfer occurs. address: 4000_8000h base + 108h offset + (16d i), where i=0d to 3d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 ce bes bed 0 req bsy done bcr w w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r bcr w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 325
dma_dsr_bcr n field descriptions field description 31 reserved this field is reserved. this read-only field is reserved and always has the value 0. 30 ce configuration error any of the following conditions causes a configuration error: ? bcr, sar, or dar does not match the requested transfer size. ? a value greater than 0f_ffffh is written to bcr. ? bits 31-20 of sar or dar are written with a value other than one of the allowed values. see sar and dar . ? ssize or dsize is set to an unsupported value. ? bcr equals 0 when the dma receives a start condition. ce is cleared at hardware reset or by writing a 1 to the done bit. 0 no configuration error exists. 1 a configuration error has occurred. 29 bes bus error on source bes is cleared at hardware reset or by writing a 1 to the done bit. 0 no bus error occurred. 1 the dma channel terminated with a bus error during the read portion of a transfer. 28 bed bus error on destination bed is cleared at hardware reset or by writing a 1 to the done bit. 0 no bus error occurred. 1 the dma channel terminated with a bus error during the write portion of a transfer. 27 reserved this field is reserved. this read-only field is reserved and always has the value 0. 26 req request 0 no request is pending or the channel is currently active. cleared when the channel is selected. 1 the dma channel has a transfer remaining and the channel is not selected. 25 bsy busy 0 dma channel is inactive. cleared when the dma has finished the last transaction. 1 bsy is set the first time the channel is enabled after a transfer is initiated. 24 done transactions done set when all dma controller transactions complete as determined by transfer count, or based on error conditions. when bcr reaches zero, done is set when the final transfer completes successfully. done can also be used to abort a transfer by resetting the status bits. when a transfer completes, software must clear done before reprogramming the dma. 0 dma transfer is not yet complete. writing a 0 has no effect. 1 dma transfer completed. writing a 1 to this bit clears all dma status bits and should be used in an interrupt service routine to clear the dma interrupt and error bits. 23C0 bcr this field contains the number of bytes yet to be transferred for a given block. restriction: bcr must be written with a value equal to or less than 0f_ffffh. after being written with a value in this range, bits 23-20 of bcr read back as 1110b. a write to bcr of a value table continues on the next page... memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 326 freescale semiconductor, inc.
dma_dsr_bcr n field descriptions (continued) field description greater than 0f_ffffh causes a configuration error when the channel starts to execute. after being written with a value in this range, bits 23-20 of bcr read back as 1111b. 23.3.4 dma control register (dma_dcr n ) address: 4000_8000h base + 10ch offset + (16d i), where i=0d to 3d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r eint erq cs aa 0 reserved eadreq sinc ssize dinc dsize 0 w start reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r smod dmod d_req 0 linkcc lch1 lch2 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 dma_dcr n field descriptions field description 31 eint enable interrupt on completion of transfer determines whether an interrupt is generated by completing a transfer or by the occurrence of an error condition. 0 no interrupt is generated. 1 interrupt signal is enabled. 30 erq enable peripheral request caution: be careful: a collision can occur between the start bit and d_req when the erq bit is 1. 0 peripheral request is ignored. 1 enables peripheral request to initiate transfer. a software-initiated request (setting the start bit) is always enabled. table continues on the next page... chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 327
dma_dcr n field descriptions (continued) field description 29 cs cycle steal 0 dma continuously makes read/write transfers until the bcr decrements to 0. 1 forces a single read/write transfer per request. 28 aa auto-align aa and size bits determine whether the source or destination is auto-aligned; that is, transfers are optimized based on the address and size. 0 auto-align disabled 1 if ssize indicates a transfer no smaller than dsize, source accesses are auto-aligned; otherwise, destination accesses are auto-aligned. source alignment takes precedence over destination alignment. if auto-alignment is enabled, the appropriate address register increments, regardless of dinc or sinc. 27C25 reserved this field is reserved. this read-only field is reserved and always has the value 0. 24 reserved this field is reserved. caution: must be written as zero; otherwise, undefined behavior results. 23 eadreq enable asynchronous dma requests enables the channel to support asynchronous dreqs while the mcu is in stop mode. 0 disabled 1 enabled 22 sinc source increment controls whether the source address increments after each successful transfer. 0 no change to sar after a successful transfer. 1 the sar increments by 1, 2, 4 as determined by the transfer size. 21C20 ssize source size determines the data size of the source bus cycle for the dma controller. 00 32-bit 01 8-bit 10 16-bit 11 reserved (generates a configuration error (dsrn[ce]) if incorrectly specified at time of channel activation) 19 dinc destination increment controls whether the destination address increments after each successful transfer. 0 no change to the dar after a successful transfer. 1 the dar increments by 1, 2, 4 depending upon the size of the transfer. 18C17 dsize destination size determines the data size of the destination bus cycle for the dma controller. 00 32-bit 01 8-bit table continues on the next page... memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 328 freescale semiconductor, inc.
dma_dcr n field descriptions (continued) field description 10 16-bit 11 reserved (generates a configuration error (dsrn[ce]) if incorrectly specified at time of channel activation) 16 start start transfer 0 dma inactive 1 the dma begins the transfer in accordance to the values in the tcdn. start is cleared automatically after one module clock and always reads as logic 0. 15C12 smod source address modulo defines the size of the source data circular buffer used by the dma controller. if enabled (smod is non- zero), the buffer base address is located on a boundary of the buffer size. the value of this boundary is based upon the initial source address (sar). the base address should be aligned to a 0-modulo-(circular buffer size) boundary. misaligned buffers are not possible. the boundary is forced to the value determined by the upper address bits in the field selection. 0000 buffer disabled 0001 circular buffer size is 16 bytes 0010 circular buffer size is 32 bytes 0011 circular buffer size is 64 bytes 0100 circular buffer size is 128 bytes 0101 circular buffer size is 256 bytes 0110 circular buffer size is 512 bytes 0111 circular buffer size is 1 kb 1000 circular buffer size is 2 kb 1001 circular buffer size is 4 kb 1010 circular buffer size is 8 kb 1011 circular buffer size is 16 kb 1100 circular buffer size is 32 kb 1101 circular buffer size is 64 kb 1110 circular buffer size is 128 kb 1111 circular buffer size is 256 kb 11C8 dmod destination address modulo defines the size of the destination data circular buffer used by the dma controller. if enabled (dmod value is non-zero), the buffer base address is located on a boundary of the buffer size. the value of this boundary depends on the initial destination address (dar). the base address should be aligned to a 0- modulo-(circular buffer size) boundary. misaligned buffers are not possible. the boundary is forced to the value determined by the upper address bits in the field selection. 0000 buffer disabled 0001 circular buffer size is 16 bytes 0010 circular buffer size is 32 bytes 0011 circular buffer size is 64 bytes 0100 circular buffer size is 128 bytes 0101 circular buffer size is 256 bytes 0110 circular buffer size is 512 bytes 0111 circular buffer size is 1 kb 1000 circular buffer size is 2 kb 1001 circular buffer size is 4 kb table continues on the next page... chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 329
dma_dcr n field descriptions (continued) field description 1010 circular buffer size is 8 kb 1011 circular buffer size is 16 kb 1100 circular buffer size is 32 kb 1101 circular buffer size is 64 kb 1110 circular buffer size is 128 kb 1111 circular buffer size is 256 kb 7 d_req disable request dma hardware automatically clears the corresponding dcrn[erq] bit when the byte count register reaches zero. 0 erq bit is not affected. 1 erq bit is cleared when the bcr is exhausted. 6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5C4 linkcc link channel control allows dma channels to have their transfers linked. the current dma channel triggers a dma request to the linked channels (lch1 or lch2) depending on the condition described by the linkcc bits. if not in cycle steal mode (dcrn[cs]=0) and linkcc equals 01 or 10, no link to lch1 occurs. if linkcc equals 01, a link to lch1 is created after each cycle-steal transfer performed by the current dma channel is completed. as the last cycle-steal is performed and the bcr reaches zero, then the link to lch1 is closed and a link to lch2 is created. 00 no channel-to-channel linking 01 perform a link to channel lch1 after each cycle-steal transfer followed by a link to lch2 after the bcr decrements to zero 10 perform a link to channel lch1 after each cycle-steal transfer 11 perform a link to channel lch1 after the bcr decrements to zero 3C2 lch1 link channel 1 indicates the dma channel assigned as link channel 1. the link channel number cannot be the same as the currently executing channel, and generates a configuration error if this is attempted (dsrn[ce] is set). 00 dma channel 0 01 dma channel 1 10 dma channel 2 11 dma channel 3 1C0 lch2 link channel 2 indicates the dma channel assigned as link channel 2. the link channel number cannot be the same as the currently executing channel, and generates a configuration error if this is attempted (dsrn[ce] is set). 00 dma channel 0 01 dma channel 1 10 dma channel 2 11 dma channel 3 memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 330 freescale semiconductor, inc.
23.4 functional description in the following discussion, the term dma request implies that dcr n [start] is set, or dcrn[erq] is set and then followed by assertion of the properly selected dma peripheral request. the start bit is cleared when the channel is activated. before initiating a dual-address access, the dma module verifies that dcr n [ssize] and dcr n [dsize] are consistent with the source and destination addresses. if they are not consistent, the configuration error bit, dsr n [ce], is set. if misalignment is detected, no transfer occurs, dsr n [ce] is set, and, depending on the dcr configuration, an interrupt event may be issued. if the auto-align bit, dcr n [aa], is set, error checking is performed on the appropriate registers. a read/write transfer sequence reads data from the source address and writes it to the destination address. the number of bytes transferred is the largest of the sizes specified by dcr n [ssize] and dcr n [dsize] in the dma control registers (dcrn). source and destination address registers (sar n and dar n ) can be programmed in the dcr n to increment at the completion of a successful transfer. 23.4.1 transfer requests (cycle-steal and continuous modes) the dma channel supports software-initiated or peripheral-initiated requests. a request is issued by setting dcr n [start] or when the selected peripheral request asserts and dcrn[erq] is set. setting dcr n [erq] enables recognition of the peripheral dma requests. selecting between cycle-steal and continuous modes minimizes bus usage for either type of request. ? cycle-steal mode (dcr n [cs] = 1)only one complete transfer from source to destination occurs for each request. if dcrn[erq] is set, the request is peripheral initiated. a software-initiated request is enabled by setting dcr n [start]. ? continuous mode (dcr n [cs] = 0)after a software-initiated or peripheral request, the dma continuously transfers data until bcrn reaches zero. the dma performs the specified number of transfers, then retires the channel. in either mode, the crossbar switch performs independent arbitration on each slave port after each transaction. chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 331
23.4.2 channel initialization and startup before a data transfer starts, the channel's transfer control descriptor must be initialized with information describing configuration, request-generation method, and pointers to the data to be moved. 23.4.2.1 channel prioritization the four dma channels are prioritized based on number, with channel 0 having highest priority and channel 3 having the lowest, that is, channel 0 > channel 1 > channel 2 > channel 3. simultaneous peripheral requests activate the channels based on this priority order. once activated, a channel runs to completion as defined by dcr n [cs] and bcr n . 23.4.2.2 programming the dma controller module caution during a channel's execution, writes to programming model registers can corrupt the data transfer. the dma module itself does not have a mechanism to prevent writes to registers during a channel's execution. general guidelines for programming the dma are: ? tcd n is initialized. ? sar n is loaded with the source (read) address. if the transfer is from a peripheral device to memory or to another peripheral, the source address is the location of the peripheral data register. if the transfer is from memory to a peripheral device or to memory, the source address is the starting address of the data block. this can be any appropriately aligned address. ? dar n is initialized with the destination (write) address. if the transfer is from a peripheral device to memory, or from memory to memory, dar n is loaded with the starting address of the data block to be written. if the transfer is from memory to a peripheral device, or from a peripheral device to a peripheral device, dar n is loaded with the address of the peripheral data register. this address can be any appropriately aligned address. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 332 freescale semiconductor, inc.
? sar n and dar n change after each data transfer depending on dcr n [ssize, dsize, sinc, dinc, smod, dmod] and the starting addresses. increment values can be 1, 2, or 4 for 8-bit, 16-bit, or 32-bit transfers, respectively. if the address register is programmed to remain unchanged, the register is not incremented after the data transfer. ? bcr n [bcr] must be loaded with the total number of bytes to be transferred. it is decremented by 1, 2, or 4 at the end of each transfer, depending on the transfer size. dsr n [done] must be cleared for channel startup. ? after the channel has been initialized, it may be started by setting dcr n [start] or a properly selected peripheral dma request, depending on the status of dcr n [erq]. for a software-initiated transfer, the channel can be started by setting dcr n [start] as part of a single 32-bit write to the last 32 bits of the tcd n ; that is, it is not required to write the dcr n with start cleared and then perform a second write to explicitly set start. ? programming the channel for a software-initiated request causes the channel to request the system bus and start transferring data immediately. if the channel is programmed for peripheral-initiated request, a properly selected peripheral dma request must be asserted before the channel begins the system bus transfers. ? the hardware can automatically clear dcr n [erq], disabling the peripheral request, when bcr n reaches zero by setting dcr n [d_req]. ? changes to dcr n are effective immediately while the channel is active. to avoid problems with changing a dma channel setup, write a one to dsr n [done] to stop the dma channel. 23.4.3 dual-address data transfer mode each channel supports dual-address transfers. dual-address transfers consist of a source data read and a destination data write. the dma controller module begins a dual-address transfer sequence after a dma request. if no error condition exists, dsr n [req] is set. ? dual-address readthe dma controller drives the sar n value onto the system address bus. if dcr n [sinc] is set, the sar n increments by the appropriate number of bytes upon a successful read cycle. when the appropriate number of read cycles complete (multiple reads if the destination size is larger than the source), the dma initiates the write portion of the transfer. if a termination error occurs, dsr n [bes, done] are set and dma transactions stop. chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 333
? dual-address writethe dma controller drives the dar n value onto the system address bus. when the appropriate number of write cycles complete (multiple writes if the source size is larger than the destination), dar n increments by the appropriate number of bytes if dcrn[dinc] is set. bcrn decrements by the appropriate number of bytes. dsr n [done] is set when bcr n reaches zero. if the bcr n is greater than zero, another read/write transfer is initiated if continuous mode is enabled (dcrn[cs] = 0). if a termination error occurs, dsr n [bed, done] are set and dma transactions stop. 23.4.4 advanced data transfer controls: auto-alignment typically, auto-alignment for dma transfers applies for transfers of large blocks of data. as a result, it does not apply for peripheral-initiated cycle-steal transfers. auto-alignment allows block transfers to occur at the optimal size based on the address, byte count, and programmed size. to use this feature, dcr n [aa] must be set. the source is auto-aligned if dcr n [ssize] indicates a transfer size larger than dcr n [dsize]. source alignment takes precedence over the destination when the source and destination sizes are equal. otherwise, the destination is auto-aligned. the address register chosen for alignment increments regardless of the increment value. configuration error checking is performed on registers not chosen for alignment. if bcr n is greater than 16, the address determines transfer size. transfers of 8 bits, 16 bits, or 32 bits are transferred until the address is aligned to the programmed size boundary, at which time accesses begin using the programmed size. if bcr n is less than 16 at the start of a transfer, the number of bytes remaining dictates transfer size. consider this example: ? aa equals 1. ? sar n equals 0x2000_0001. ? bcr n equals 0x00_00f0. ? ssize equals 00 (32 bits). ? dsize equals 01 (8 bits). because ssize > dsize, the source is auto-aligned. error checking is performed on destination registers. the access sequence is as follows: 1. read 1 byte from 0x2000_0001, increment sar n , write 1 byte (using dar n ). 2. read 2 bytes from 0x2000_0002, increment sar n , write 2 bytes. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 334 freescale semiconductor, inc.
3. read 4 bytes from 0x2000_0004, increment sar n , write 4 bytes. 4. repeat 4-byte operations until sar n equals 0x2000_00f0. 5. read byte from 0x2000_00f0, increment sar n , write byte. if dsize is another size, data writes are optimized to write the largest size allowed based on the address, but not exceeding the configured size. 23.4.5 termination an unsuccessful transfer can terminate for one of the following reasons: ? error conditionswhen the dma encounters a read or write cycle that terminates with an error condition, dsr n [bes] is set for a read and dsr n [bed] is set for a write before the transfer is halted. if the error occurred in a write cycle, data in the internal holding registers is lost. ? interruptsif dcr n [eint] is set, the dma drives the appropriate interrupt request signal. the processor can read dsr n to determine whether the transfer terminated successfully or with an error. dsr n [done] is then written with a one to clear the interrupt, the done, and error status bits. chapter 23 dma controller module kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 335
functional description kl04 sub-family reference manual, rev. 3.1, november 2012 336 freescale semiconductor, inc.
chapter 24 multipurpose clock generator (mcg) 24.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the multipurpose clock generator (mcg) module provides several clock source choices for the mcu. the module contains a frequency-locked loop (fll). the fll is controllable by either an internal or an external reference clock. the module can select either of the fll orthe internal or external reference clocks as a source for the mcu system clock. the mcg operates in conjuction with a crystal oscillator, which allows an external crystal, ceramic resonator, or another external clock source to produce the external reference clock. 24.1.1 features key features of the mcg module are: ? frequency-locked loop (fll): ? digitally-controlled oscillator (dco) ? dco frequency range is programmable for up to four different frequency ranges. ? option to program and maximize dco output frequency for a low frequency external reference clock source. ? option to prevent fll from resetting its current locked frequency when switching clock modes if fll reference frequency is not changed. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 337
? internal or external reference clock can be used as the fll source. ? can be used as a clock source for other on-chip peripherals. ? internal reference clock generator: ? slow clock with nine trim bits for accuracy ? fast clock with four trim bits ? can be used as source clock for the fll. in fei mode, only the slow internal reference clock (irc) can be used as the fll source. ? either the slow or the fast clock can be selected as the clock source for the mcu. ? can be used as a clock source for other on-chip peripherals. ? control signals for the mcg external reference low power oscillator clock generators are provided: ? hgo0, range0, erefs0 ? external clock from the crystal oscillator : ? can be used as a source for the fll. ? can be selected as the clock source for the mcu. ? external clock monitor with reset and interrupt request capability to check for external clock failure when running in fbe, blpe, or fee modes ? internal reference clocks auto trim machine (atm) capability using an external clock as a reference ? reference dividers for the fll are provided ? reference dividers for the fast internal reference clock are provided ? mcg fll clock (mcgfllclk) is provided as a clock source for other on-chip peripherals ? mcg fixed frequency clock (mcgffclk) is provided as a clock source for other on-chip peripherals ? mcg internal reference clock (mcgirclk) is provided as a clock source for other on-chip peripherals introduction kl04 sub-family reference manual, rev. 3.1, november 2012 338 freescale semiconductor, inc.
mcgoutclk mcgirclk mcgffclk dcoout multipurpose clock generator (mcg) clock monitor irclken cme0 / 2 5 fll dmx32 mcgfllclk crystal oscillator frdiv n=0-7 / 2 n internal reference slow clock fast clock clock generator sync auto trim machine atms sctrim scftrim fctrim irefsten oscinit0 erefs0 hgo0 range0 external drs clock valid peripheral busclk ircsclk ircs clksclks dco lp filter irefs stop clks irefs mcg crystal oscillator enable detect external reference clock n=0-7 / 2 n fltprsrv locre0 locs0 figure 24-1. multipurpose clock generator (mcg) block diagram chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 339
24.1.2 modes of operation the mcg has the following modes of operation: fei, fee, fbi, fbe, blpi, blpe, and stop. for details, see mcg modes of operation . 24.2 external signal description there are no mcg signals that connect off chip. 24.3 memory map/register definition this section includes the memory map and register definition. the mcg registers can only be written when in supervisor mode. write accesses when in user mode will result in a bus error. read accesses may be performed in both supervisor and user mode. mcg memory map absolute address (hex) register name width (in bits) access reset value section/ page 4006_4000 mcg control 1 register (mcg_c1) 8 r/w 04h 24.3.1/340 4006_4001 mcg control 2 register (mcg_c2) 8 r/w 80h 24.3.2/342 4006_4002 mcg control 3 register (mcg_c3) 8 r/w undefined 24.3.3/343 4006_4003 mcg control 4 register (mcg_c4) 8 r/w undefined 24.3.4/343 4006_4005 mcg control 6 register (mcg_c6) 8 r/w 00h 24.3.5/345 4006_4006 mcg status register (mcg_s) 8 r 10h 24.3.6/345 4006_4008 mcg status and control register (mcg_sc) 8 r/w 02h 24.3.7/346 4006_400a mcg auto trim compare value high register (mcg_atcvh) 8 r/w 00h 24.3.8/348 4006_400b mcg auto trim compare value low register (mcg_atcvl) 8 r/w 00h 24.3.9/348 24.3.1 mcg control 1 register (mcg_c1) address: 4006_4000h base + 0h offset = 4006_4000h bit 7 6 5 4 3 2 1 0 read clks frdiv irefs irclken irefsten write reset 0 0 0 0 0 1 0 0 external signal description kl04 sub-family reference manual, rev. 3.1, november 2012 340 freescale semiconductor, inc.
mcg_c1 field descriptions field description 7C6 clks clock source select selects the clock source for mcgoutclk . 00 encoding 0 output of fll is selected. 01 encoding 1 internal reference clock is selected. 10 encoding 2 external reference clock is selected. 11 encoding 3 reserved. 5C3 frdiv fll external reference divider selects the amount to divide down the external reference clock for the fll. the resulting frequency must be in the range 31.25 khz to 39.0625 khz (this is required when fll/dco is the clock source for mcgoutclk . in fbe mode, it is not required to meet this range, but it is recommended in the cases when trying to enter a fll mode from fbe). 000 if range 0 = 0 , divide factor is 1; for all other range 0 values, divide factor is 32. 001 if range 0 = 0 , divide factor is 2; for all other range 0 values, divide factor is 64. 010 if range 0 = 0 , divide factor is 4; for all other range 0 values, divide factor is 128. 011 if range 0 = 0 , divide factor is 8; for all other range 0 values, divide factor is 256. 100 if range 0 = 0 , divide factor is 16; for all other range 0 values, divide factor is 512. 101 if range 0 = 0 , divide factor is 32; for all other range 0 values, divide factor is 1024. 110 if range 0 = 0 , divide factor is 64; for all other range 0 values, divide factor is 1280 . 111 if range 0 = 0 , divide factor is 128; for all other range 0 values, divide factor is 1536 . 2 irefs internal reference select selects the reference clock source for the fll. 0 external reference clock is selected. 1 the slow internal reference clock is selected. 1 irclken internal reference clock enable enables the internal reference clock for use as mcgirclk. 0 mcgirclk inactive. 1 mcgirclk active. 0 irefsten internal reference stop enable controls whether or not the internal reference clock remains enabled when the mcg enters stop mode. 0 internal reference clock is disabled in stop mode. 1 internal reference clock is enabled in stop mode if irclken is set or if mcg is in fei, fbi, or blpi modes before entering stop mode. chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 341
24.3.2 mcg control 2 register (mcg_c2) address: 4006_4000h base + 1h offset = 4006_4001h bit 7 6 5 4 3 2 1 0 read locre0 0 range0 hgo0 erefs0 lp ircs write reset 1 0 0 0 0 0 0 0 mcg_c2 field descriptions field description 7 locre0 loss of clock reset enable determines whether an interrupt or a reset request is made following a loss of osc0 external reference clock. the locre0 only has an affect when cme0 is set. 0 interrupt request is generated on a loss of osc0 external reference clock. 1 generate a reset request on a loss of osc0 external reference clock. 6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5C4 range0 frequency range select selects the frequency range for the crystal oscillator or external clock source. see the oscillator (osc) chapter for more details and the device data sheet for the frequency ranges used. 00 encoding 0 low frequency range selected for the crystal oscillator . 01 encoding 1 high frequency range selected for the crystal oscillator . 1x encoding 2 very high frequency range selected for the crystal oscillator . 3 hgo0 high gain oscillator select controls the crystal oscillator mode of operation. see the oscillator (osc) chapter for more details. 0 configure crystal oscillator for low-power operation. 1 configure crystal oscillator for high-gain operation. 2 erefs0 external reference select selects the source for the external reference clock. see the oscillator (osc) chapter for more details. 0 external reference clock requested. 1 oscillator requested. 1 lp low power select controls whether the fll is disabled in blpi and blpe modes. in fbe mode, setting this bit to 1 will transition the mcg into blpe mode; in fbi mode, setting this bit to 1 will transition the mcg into blpi mode. in any other mcg mode, lp bit has no affect. 0 fll is not disabled in bypass modes. 1 fll is disabled in bypass modes (lower power) 0 ircs internal reference clock select selects between the fast or slow internal reference clock source. table continues on the next page... memory map/register definition kl04 sub-family reference manual, rev. 3.1, november 2012 342 freescale semiconductor, inc.
mcg_c2 field descriptions (continued) field description 0 slow internal reference clock selected. 1 fast internal reference clock selected. 24.3.3 mcg control 3 register (mcg_c3) address: 4006_4000h base + 2h offset = 4006_4002h bit 7 6 5 4 3 2 1 0 read sctrim write reset x* x* x* x* x* x* x* x* * notes: x = undefined at reset. ? mcg_c3 field descriptions field description 7C0 sctrim slow internal reference clock trim setting sctrim 1 controls the slow internal reference clock frequency by controlling the slow internal reference clock period. the sctrim bits are binary weighted, that is, bit 1 adjusts twice as much as bit 0. increasing the binary value increases the period, and decreasing the value decreases the period. an additional fine trim bit is available in c4 register as the scftrim bit. upon reset, this value is loaded with a factory trim value. if an sctrim value stored in nonvolatile memory is to be used, it is your responsibility to copy that value from the nonvolatile memory location to this register. 1. a value for sctrim is loaded during reset from a factory programmed location . 24.3.4 mcg control 4 register (mcg_c4) note reset values for drst and dmx32 bits are 0. address: 4006_4000h base + 3h offset = 4006_4003h bit 7 6 5 4 3 2 1 0 read dmx32 drst_drs fctrim scftrim write reset 0 0 0 x* x* x* x* x* * notes: x = undefined at reset. ? a value for fctrim is loaded during reset from a factory programmed location . x = undefined at reset. ? chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 343
mcg_c4 field descriptions field description 7 dmx32 dco maximum frequency with 32.768 khz reference the dmx32 bit controls whether the dco frequency range is narrowed to its maximum frequency with a 32.768 khz reference. the following table identifies settings for the dco frequency range. note: the system clocks derived from this source should not exceed their specified maximums. drst_drs dmx32 reference range fll factor dco range 00 0 31.25C39.0625 khz 640 20C25 mhz 1 32.768 khz 732 24 mhz 01 0 31.25C39.0625 khz 1280 40C50 mhz 1 32.768 khz 1464 48 mhz 10 0 31.25C39.0625 khz 1920 60C75 mhz 1 32.768 khz 2197 72 mhz 11 0 31.25C39.0625 khz 2560 80C100 mhz 1 32.768 khz 2929 96 mhz 0 dco has a default range of 25%. 1 dco is fine-tuned for maximum frequency with 32.768 khz reference. 6C5 drst_drs dco range select the drs bits select the frequency range for the fll output, dcoout. when the lp bit is set, writes to the drs bits are ignored. the drst read field indicates the current frequency range for dcoout. the drst field does not update immediately after a write to the drs field due to internal synchronization between clock domains. see the dco frequency range table for more details. 00 encoding 0 low range (reset default). 01 encoding 1 mid range. 10 encoding 2 mid-high range. 11 encoding 3 high range. 4C1 fctrim fast internal reference clock trim setting fctrim 1 controls the fast internal reference clock frequency by controlling the fast internal reference clock period. the fctrim bits are binary weighted, that is, bit 1 adjusts twice as much as bit 0. increasing the binary value increases the period, and decreasing the value decreases the period. if an fctrim[3:0] value stored in nonvolatile memory is to be used, it is your responsibility to copy that value from the nonvolatile memory location to this register. 0 scftrim slow internal reference clock fine trim scftrim 2 controls the smallest adjustment of the slow internal reference clock frequency. setting scftrim increases the period and clearing scftrim decreases the period by the smallest amount possible. if an scftrim value stored in nonvolatile memory is to be used, it is your responsibility to copy that value from the nonvolatile memory location to this bit. 1. a value for fctrim is loaded during reset from a factory programmed location . 2. a value for scftrim is loaded during reset from a factory programmed location . memory map/register definition kl04 sub-family reference manual, rev. 3.1, november 2012 344 freescale semiconductor, inc.
24.3.5 mcg control 6 register (mcg_c6) address: 4006_4000h base + 5h offset = 4006_4005h bit 7 6 5 4 3 2 1 0 read 0 cme 0 write reset 0 0 0 0 0 0 0 0 mcg_c6 field descriptions field description 7C6 reserved reserved this field is reserved. this read-only field is reserved and always has the value 0. 5 cme clock monitor enable determines if a reset request is made following a loss of external clock indication. the cme bit should only be set to a logic 1 when the mcg is in an operational mode that uses the external clock (fee, fbe, pee, pbe, or blpe). whenever the cme bit is set to a logic 1, the value of the range bits in the c2 register should not be changed. cme bit should be set to a logic 0 before the mcg enters any stop mode. otherwise, a reset request may occur when in stop mode. cme should also be set to a logic 0 before entering vlpr or vlpw power modes if the mcg is in blpe mode. 0 external clock monitor is disabled. 1 generate a reset request on loss of external clock. 4C0 reserved reserved this field is reserved. this read-only field is reserved and always has the value 0. 24.3.6 mcg status register (mcg_s) address: 4006_4000h base + 6h offset = 4006_4006h bit 7 6 5 4 3 2 1 0 read 0 irefst clkst oscinit0 ircst write reset 0 0 0 1 0 0 0 0 mcg_s field descriptions field description 7C5 reserved reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 345
mcg_s field descriptions (continued) field description 4 irefst internal reference status this bit indicates the current source for the fll reference clock. the irefst bit does not update immediately after a write to the irefs bit due to internal synchronization between clock domains. 0 source of fll reference clock is the external reference clock. 1 source of fll reference clock is the internal reference clock. 3C2 clkst clock mode status these bits indicate the current clock mode. the clkst bits do not update immediately after a write to the clks bits due to internal synchronization between clock domains. 00 encoding 0 output of the fll is selected (reset default). 01 encoding 1 internal reference clock is selected. 10 encoding 2 external reference clock is selected. 11 reserved. 1 oscinit0 osc initialization this bit, which resets to 0, is set to 1 after the initialization cycles of the crystal oscillator clock have completed. after being set, the bit is cleared to 0 if the osc is subsequently disabled. see the osc module's detailed description for more information. 0 ircst internal reference clock status the ircst bit indicates the current source for the internal reference clock select clock (ircsclk). the ircst bit does not update immediately after a write to the ircs bit due to internal synchronization between clock domains. the ircst bit will only be updated if the internal reference clock is enabled, either by the mcg being in a mode that uses the irc or by setting the c1[irclken] bit . 0 source of internal reference clock is the slow clock (32 khz irc). 1 source of internal reference clock is the fast clock (4 mhz irc). 24.3.7 mcg status and control register (mcg_sc) address: 4006_4000h base + 8h offset = 4006_4008h bit 7 6 5 4 3 2 1 0 read atme atms atmf fltprsrv fcrdiv locs0 write reset 0 0 0 0 0 0 1 0 mcg_sc field descriptions field description 7 atme automatic trim machine enable enables the auto trim machine to start automatically trimming the selected internal reference clock. note: atme deasserts after the auto trim machine has completed trimming all trim bits of the ircs clock selected by the atms bit. table continues on the next page... memory map/register definition kl04 sub-family reference manual, rev. 3.1, november 2012 346 freescale semiconductor, inc.
mcg_sc field descriptions (continued) field description writing to c1, c3, c4, and sc registers or entering stop mode aborts the auto trim operation and clears this bit. 0 auto trim machine disabled. 1 auto trim machine enabled. 6 atms automatic trim machine select selects the ircs clock for auto trim test. 0 32 khz internal reference clock selected. 1 4 mhz internal reference clock selected. 5 atmf automatic trim machine fail flag fail flag for the automatic trim machine (atm). this bit asserts when the automatic trim machine is enabled, atme=1, and a write to the c1, c3, c4, and sc registers is detected or the mcg enters into any stop mode. a write to atmf clears the flag. 0 automatic trim machine completed normally. 1 automatic trim machine failed. 4 fltprsrv fll filter preserve enable this bit will prevent the fll filter values from resetting allowing the fll output frequency to remain the same during clock mode changes where the fll/dco output is still valid. (note: this requires that the fll reference frequency to remain the same as what it was prior to the new clock mode switch. otherwise fll filter and frequency values will change.) 0 fll filter and fll frequency will reset on changes to currect clock mode. 1 fll filter and fll frequency retain their previous values during new clock mode change. 3C1 fcrdiv fast clock internal reference divider selects the amount to divide down the fast internal reference clock. the resulting frequency will be in the range 31.25 khz to 4 mhz (note: changing the divider when the fast irc is enabled is not supported). 000 divide factor is 1 001 divide factor is 2. 010 divide factor is 4. 011 divide factor is 8. 100 divide factor is 16 101 divide factor is 32 110 divide factor is 64 111 divide factor is 128. 0 locs0 osc0 loss of clock status the locs0 indicates when a loss of osc0 reference clock has occurred. the locs0 bit only has an effect when cme0 is set. this bit is cleared by writing a logic 1 to it when set. 0 loss of osc0 has not occurred. 1 loss of osc0 has occurred. chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 347
24.3.8 mcg auto trim compare value high register (mcg_atcvh) address: 4006_4000h base + ah offset = 4006_400ah bit 7 6 5 4 3 2 1 0 read atcvh write reset 0 0 0 0 0 0 0 0 mcg_atcvh field descriptions field description 7C0 atcvh atm compare value high values are used by auto trim machine to compare and adjust internal reference trim values during atm sar conversion. 24.3.9 mcg auto trim compare value low register (mcg_atcvl) address: 4006_4000h base + bh offset = 4006_400bh bit 7 6 5 4 3 2 1 0 read atcvl write reset 0 0 0 0 0 0 0 0 mcg_atcvl field descriptions field description 7C0 atcvl atm compare value low values are used by auto trim machine to compare and adjust internal reference trim values during atm sar conversion. functional description 24.4.1 mcg mode state diagram the seven states of the mcg are shown in the following figure and are described in table 24-11 . the arrows indicate the permitted mcg mode transitions. 24.4 functional description kl04 sub-family reference manual, rev. 3.1, november 2012 348 freescale semiconductor, inc.
fee fei reset blpi fbi fbe blpe stop returns to the state that was active before the mcu entered stop mode, unless a reset occurs while in stop mode. entered from any state when the mcu enters stop mode figure 24-11. mcg mode state diagram 24.4.1.1 mcg modes of operation the mcg operates in one of the following modes. note the mcg restricts transitions between modes. for the permitted transitions, see figure 24-11 . table 24-11. mcg modes of operation mode description fll engaged internal (fei) fll engaged internal (fei) is the default mode of operation and is entered when all the following condtions occur: ? c1[clks] bits are written to 00 ? c1[irefs] bit is written to 1 in fei mode, mcgoutclk is derived from the fll clock (dcoclk) that is controlled by the 32 khz internal reference clock (irc). the fll loop will lock the dco frequency to the fll factor, as selected by c4[drst_drs] and c4[dmx32] bits, times the internal reference frequency. see the c4[dmx32] bit description for more details. table continues on the next page... chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 349
table 24-11. mcg modes of operation (continued) mode description fll engaged external (fee) fll engaged external (fee) mode is entered when all the following conditions occur: ? c1[clks] bits are written to 00 ? c1[irefs] bit is written to 0 ? c1[frdiv] must be written to divide external reference clock to be within the range of 31.25 khz to 39.0625 khz in fee mode, mcgoutclk is derived from the fll clock (dcoclk) that is controlled by the external reference clock. the fll loop will lock the dco frequency to the fll factor, as selected by c4[drst_drs] and c4[dmx32] bits, times the external reference frequency, as specified by c1[frdiv] and c2[range0]. see the c4[dmx32] bit description for more details. fll bypassed internal (fbi) fll bypassed internal (fbi) mode is entered when all the following conditions occur: ? c1[clks] bits are written to 01 ? c1[irefs] bit is written to 1 ? c2[lp] is written to 0 in fbi mode, the mcgoutclk is derived either from the slow (32 khz irc) or fast (4 mhz irc) internal reference clock, as selected by the c2[ircs] bit. the fll is operational but its output is not used. this mode is useful to allow the fll to acquire its target frequency while the mcgoutclk is driven from the c2[ircs] selected internal reference clock. the fll clock (dcoclk) is controlled by the slow internal reference clock, and the dco clock frequency locks to a multiplication factor, as selected by c4[drst_drs] and c4[dmx32] bits, times the internal reference frequency. see the c4[dmx32] bit description for more details. fll bypassed external (fbe) fll bypassed external (fbe) mode is entered when all the following conditions occur: ? c1[clks] bits are written to 10 ? c1[irefs] bit is written to 0 ? c1[frdiv] must be written to divide external reference clock to be within the range of 31.25 khz to 39.0625 khz. ? c2[lp] is written to 0 in fbe mode, the mcgoutclk is derived from the external reference clock. the fll is operational but its output is not used. this mode is useful to allow the fll to acquire its target frequency while the mcgoutclk is driven from the external reference clock. the fll clock (dcoclk) is controlled by the external reference clock, and the dco clock frequency locks to a multiplication factor, as selected by c4[drst_drs] and c4[dmx32] bits, times the divided external reference frequency. see the c4[dmx32] bit description for more details. bypassed low power internal (blpi) 1 bypassed low power internal (blpi) mode is entered when all the following conditions occur: ? c1[clks] bits are written to 01 ? c1[irefs] bit is written to 1 ? c2[lp] bit is written to 1 in blpi mode, mcgoutclk is derived from the internal reference clock. the fll is disabled table continues on the next page... functional description kl04 sub-family reference manual, rev. 3.1, november 2012 350 freescale semiconductor, inc.
table 24-11. mcg modes of operation (continued) mode description bypassed low power external (blpe) bypassed low power external (blpe) mode is entered when all the following conditions occur: ? c1[clks] bits are written to 10 ? c1[irefs] bit is written to 0 ? c2[lp] bit is written to 1 in blpe mode, mcgoutclk is derived from the external reference clock. the fll is disabled stop entered whenever the mcu enters a stop state. the power modes are chip specific. for power mode assignments, see the chapter that describes how modules are configured and mcg behavior during stop recovery. entering stop mode, the fll is disabled, and all mcg clock signals are static except in the following case: mcgirclk is active in normal stop mode when all the following conditions become true: ? c1[irclken] = 1 ? c1[irefsten] = 1 1. if entering vlpr mode, mcg has to be configured and enter blpe mode or blpi mode with the fast irc clock selected (c2[ircs]=1). after it enters vlpr mode, writes to any of the mcg control registers that can cause an mcg clock mode switch to a non low power clock mode must be avoided. note for the chip-specific modes of operation, see the power management chapter of this mcu. 24.4.1.2 mcg mode switching the c1[irefs] bit can be changed at any time, but the actual switch to the newly selected reference clocks is shown by the s[irefst] bit. when switching between engaged internal and engaged external modes, the fll will begin locking again after the switch is completed. the c1[clks] bits can also be changed at any time, but the actual switch to the newly selected clock is shown by the s[clkst] bits. if the newly selected clock is not available, the previous clock will remain selected. the c4[drst_drs] write bits can be changed at any time except when c2[lp] bit is 1. if the c4[drst_drs] write bits are changed while in fll engaged internal (fei) or fll engaged external (fee), the mcgoutclk will switch to the new selected dco range within three clocks of the selected dco clock. after switching to the new dco, the fll remains unlocked for several reference cycles. dco startup time is equal to the fll acquisition time. after the selected dco startup time is over, the fll is locked. the completion of the switch is shown by the c4[drst_drs] read bits. chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 351
24.4.2 low power bit usage the c2[lp] bit is provided to allow the fll to be disabled and thus conserve power when these systems are not being used. the c4[drst_drs] can not be written while c2[lp] bit is 1. however, in some applications, it may be desirable to enable the fll and allow it to lock for maximum accuracy before switching to an engaged mode. do this by writing c2[lp] to 0. 24.4.3 mcg internal reference clocks this module supports two internal reference clocks with nominal frequencies of 32 khz (slow irc) and 4 mhz (fast irc). the fast irc frequency can be divided down by programming of the fcrdiv to produce a frequency range of 32 khz to 4 mhz. 24.4.3.1 mcg internal reference clock the mcg internal reference clock (mcgirclk) provides a clock source for other on- chip peripherals and is enabled when c1[irclken]=1. when enabled, mcgirclk is driven by either the fast internal reference clock (4 mhz irc which can be divided down by the frdiv factors) or the slow internal reference clock (32 khz irc). the ircs clock frequency can be re-targeted by trimming the period of its ircs selected internal reference clock. this can be done by writing a new trim value to the c3[sctrim]:c4[scftrim] bits when the slow irc clock is selected or by writing a new trim value to the c4[fctrim] bits when the fast irc clock is selected. the internal reference clock period is proportional to the trim value written. c3[sctrim]:c4[scftrim] (if c2[ircs]=0) and c4[fctrim] (if c2[ircs]=1) bits affect the mcgoutclk frequency if the mcg is in fbi or blpi modes. c3[sctrim]:c4[scftrim] (if c2[ircs]=0) bits also affect the mcgoutclk frequency if the mcg is in fei mode. additionally, this clock can be enabled in stop mode by setting c1[irclken] and c1[irefsten], otherwise this clock is disabled in stop mode. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 352 freescale semiconductor, inc.
24.4.4 external reference clock the mcg module can support an external reference clock in all modes. see the device datasheet for external reference frequency range. when c1[irefs] is set, the external reference clock will not be used by the fll. in these mode, the frequency can be equal to the maximum frequency the chip-level timing specifications will support. if any of the cme bits are asserted the slow internal reference clock is enabled along with the enabled external clock monitor. for the case when c6[cme0]=1, a loss of clock is detected if the osc0 external reference falls below a minimum frequency (f loc_high or f loc_low depending on c2[range0]). note all clock monitors must be disabled before entering these low- power modes: stop, vlps, vlpr, vlpw, lls, and vllsx. upon detect of a loss of clock event, the mcu generates a system reset if the respective locre bit is set. otherwise the mcg sets the respective locs bit and the mcg generates a locs interrupt request. 24.4.5 mcg fixed frequency clock the mcg fixed frequency clock (mcgffclk) provides a fixed frequency clock source for other on-chip peripherals; see the block diagram. this clock is driven by either the slow clock from the internal reference clock generator or the external reference clock from the crystal oscillator, divided by the fll reference clock divider. the source of mcgffclk is selected by c1[irefs]. this clock is synchronized to the peripheral bus clock and is valid only when its frequency is not more than 1/8 of the mcgoutclk frequency. when it is not valid, it is disabled and held high. the mcgffclk is not available when the mcg is in blpi mode. this clock is also disabled in stop mode. the fll reference clock must be set within the valid frequency range for the mcgffclk. 24.4.6 mcg auto trim (atm) the mcg auto trim (atm) is a mcg feature that when enabled, it configures the mcg hardware to automatically trim the mcg internal reference clocks using an external clock as a reference. the selection between which mcg irc clock gets tested and chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 353
enabled is controlled by the atc[atms] control bit (atc[atms]=0 selects the 32 khz irc and atc[atms]=1 selects the 4 mhz irc). if 4 mhz irc is selected for the atm, a divide by 128 is enabled to divide down the 4 mhz irc to a range of 31.250 khz. when mcg atm is enabled by writing atc[atme] bit to 1, the atm machine will start auto trimming the selected irc clock. during the autotrim process, atc[atme] will remain asserted and will deassert after atm is completed or an abort occurs. the mcg atm is aborted if a write to any of the following control registers is detected : c1, c3, c4, or atc or if stop mode is entered. if an abort occurs, atc[atmf] fail flag is asserted. the atm machine uses the bus clock as the external reference clock to perform the irc auto-trim. therefore, it is required that the mcg is configured in a clock mode where the reference clock used to generate the system clock is the external reference clock such as fbe clock mode. the mcg must not be configured in a clock mode where selected irc atm clock is used to generate the system clock. the bus clock is also required to be running with in the range of 8C16 mhz. to perform the atm on the selected irc, the atm machine uses the successive approximation technique to adjust the irc trim bits to generate the desired irc trimmed frequency. the atm sars each of the atm irc trim bits starting with the msb. for each trim bit test, the atm uses a pulse that is generated by the atm selected irc clock to enable a counter that counts number of atm external clocks. at end of each trim bit, the atm external counter value is compared to the atcv[15:0] register value. based on the comparison result, the atm trim bit under test will get cleared or stay asserted. this is done until all trim bits have been tested by atm sar machine. before the atm can be enabled, the atm expected count needs to be derived and stored into the atcv register. the atcv expected count is derived based on the required target internal reference clock (irc) frequency, and the frequency of the external reference clock using the following formula: atcv ? fr = target internal reference clock (irc) trimmed frequency ? fe = external clock frequency if the auto trim is being performed on the 4 mhz irc, the calculated expected count value must be multiplied by 128 before storing it in the atcv register. therefore, the atcv expected count value for trimming the 4 mhz irc is calculated using the following formula. (128) functional description kl04 sub-family reference manual, rev. 3.1, november 2012 354 freescale semiconductor, inc.
24.5 initialization / application information this section describes how to initialize and configure the mcg module in an application. the following sections include examples on how to initialize the mcg and properly switch between the various available modes. 24.5.1 mcg module initialization sequence the mcg comes out of reset configured for fei mode. the internal reference will stabilize in t irefsts microseconds before the fll can acquire lock. as soon as the internal reference is stable, the fll will acquire lock in t fll_acquire milliseconds. 24.5.1.1 initializing the mcg because the mcg comes out of reset in fei mode, the only mcg modes that can be directly switched to upon reset are fee, fbe, and fbi modes (see figure 24-11 ). reaching any of the other modes requires first configuring the mcg for one of these three intermediate modes. care must be taken to check relevant status bits in the mcg status register reflecting all configuration changes within each mode. to change from fei mode to fee or fbe modes, follow this procedure: 1. enable the external clock source by setting the appropriate bits in c2 register. 2. write to c1 register to select the clock mode. ? if entering fee mode, set c1[frdiv] appropriately, clear the c1[irefs] bit to switch to the external reference, and leave the c1[clks] bits at 2'b00 so that the output of the fll is selected as the system clock source. ? if entering fbe, clear the c1[irefs] bit to switch to the external reference and change the c1[clks] bits to 2'b10 so that the external reference clock is selected as the system clock source. the c1[frdiv] bits should also be set chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 355
appropriately here according to the external reference frequency to keep the fll reference clock in the range of 31.25 khz to 39.0625 khz. although the fll is bypassed, it is still on in fbe mode. ? the internal reference can optionally be kept running by setting the c1[irclken] bit. this is useful if the application will switch back and forth between internal and external modes. for minimum power consumption, leave the internal reference disabled while in an external clock mode. 3. once the proper configuration bits have been set, wait for the affected bits in the mcg status register to be changed appropriately, reflecting that the mcg has moved into the proper mode. ? if the mcg is in fee, fbe, or blpe mode, and c2[erefs0] was also set in step 1, wait here for s[oscinit0] bit to become set indicating that the external clock source has finished its initialization cycles and stabilized. ? if in fee mode, check to make sure the s[irefst] bit is cleared before moving on. ? if in fbe mode, check to make sure the s[irefst] bit is cleared and s[clkst] bits have changed to 2'b10 indicating the external reference clock has been appropriately selected. although the fll is bypassed, it is still on in fbe mode. 4. write to the c4 register to determine the dco output (mcgfllclk) frequency range. ? by default, with c4[dmx32] cleared to 0, the fll multiplier for the dco output is 640. for greater flexibility, if a mid-low-range fll multiplier of 1280 is desired instead, set c4[drst_drs] bits to 2'b01 for a dco output frequency of 40 mhz. if a mid high-range fll multiplier of 1920 is desired instead, set the c4[drst_drs] bits to 2'b10 for a dco output frequency of 60 mhz. if a high- range fll multiplier of 2560 is desired instead, set the c4[drst_drs] bits to 2'b11 for a dco output frequency of 80 mhz. ? when using a 32.768 khz external reference, if the maximum low-range dco frequency that can be achieved with a 32.768 khz reference is desired, set c4[drst_drs] bits to 2'b00 and set c4[dmx32] bit to 1. the resulting dco output (mcgoutclk) frequency with the new multiplier of 732 will be 24 mhz. initialization / application information kl04 sub-family reference manual, rev. 3.1, november 2012 356 freescale semiconductor, inc.
? when using a 32.768 khz external reference, if the maximum mid-range dco frequency that can be achieved with a 32.768 khz reference is desired, set c4[drst_drs] bits to 2'b01 and set c4[dmx32] bit to 1. the resulting dco output (mcgoutclk) frequency with the new multiplier of 1464 will be 48 mhz. ? when using a 32.768 khz external reference, if the maximum mid high-range dco frequency that can be achieved with a 32.768 khz reference is desired, set c4[drst_drs] bits to 2'b10 and set c4[dmx32] bit to 1. the resulting dco output (mcgoutclk) frequency with the new multiplier of 2197 will be 72 mhz. ? when using a 32.768 khz external reference, if the maximum high-range dco frequency that can be achieved with a 32.768 khz reference is desired, set c4[drst_drs] bits to 2'b11 and set c4[dmx32] bit to 1. the resulting dco output (mcgoutclk) frequency with the new multiplier of 2929 will be 96 mhz. 5. wait for the fll lock time to guarantee fll is running at new c4[drst_drs] and c4[dmx32] programmed frequency. to change from fei clock mode to fbi clock mode, follow this procedure: 1. change c1[clks] bits in c1 register to 2'b01 so that the internal reference clock is selected as the system clock source. 2. wait for s[clkst] bits in the mcg status register to change to 2'b01, indicating that the internal reference clock has been appropriately selected. 3. write to the c2 register to determine the ircs output (ircsclk) frequency range. ? by default, with c2[ircs] cleared to 0, the ircs selected output clock is the slow internal reference clock (32 khz irc). if the faster irc is desired, set c2[ircs] bit to 1 for a ircs clock derived from the 4 mhz irc source. 24.5.2 using a 32.768 khz reference in fee and fbe modes, if using a 32.768 khz external reference, at the default fll multiplication factor of 640, the dco output (mcgfllclk) frequency is 20.97 mhz at low-range. if c4[drst_drs] bits are set to 2'b01, the multiplication factor is doubled to 1280, and the resulting dco output frequency is 41.94 mhz at mid-low-range. if c4[drst_drs] bits are set to 2'b10, the multiplication factor is set to 1920, and the chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 357
resulting dco output frequency is 62.91 mhz at mid high-range. if c4[drst_drs] bits are set to 2'b11, the multiplication factor is set to 2560, and the resulting dco output frequency is 83.89 mhz at high-range. in fbi and fei modes, setting c4[dmx32] bit is not recommended. if the internal reference is trimmed to a frequency above 32.768 khz, the greater fll multiplication factor could potentially push the microcontroller system clock out of specification and damage the part. 24.5.3 mcg mode switching when switching between operational modes of the mcg, certain configuration bits must be changed in order to properly move from one mode to another. each time any of these bits are changed (c1[irefs], c1[clks], c2[ircs], or c2[erefs0]), the corresponding bits in the mcg status register (irefst, clkst, ircst, or oscinit) must be checked before moving on in the application software. additionally, care must be taken to ensure that the reference clock divider (c1[frdiv]) is set properly for the mode being switched to. for instance, in fee mode, if using a 4mhz crystal, c1[frdiv] must be set to 3'b010 (divide-by-128) to devide the external frequency down to the required frequency between 31.25 and 39.0625 khz. in fbe, fee, fbi, and fei modes, at any time, the application can switch the fll multiplication factor between 640, 1280, 1920, and 2560 with c4[drst_drs] bits. writes to c4[drst_drs] bits will be ignored if c2[lp]=1. the table below shows mcgoutclk frequency calculations using c1[frdiv]settings for each clock mode. table 24-12. mcgoutclk frequency calculation options clock mode f mcgoutclk 1 note fei (fll engaged internal) (f int * f) typical f mcgoutclk = 21 mhz immediately after reset. fee (fll engaged external) (f ext / fll_r) *f f ext / fll_r must be in the range of 31.25 khz to 39.0625 khz fbe (fll bypassed external) oscclk oscclk / fll_r must be in the range of 31.25 khz to 39.0625 khz fbi (fll bypassed internal) mcgirclk selectable between slow and fast irc blpi (bypassed low power internal) mcgirclk selectable between slow and fast irc blpe (bypassed low power external) oscclk 1. fll_r is the reference divider selected by the c1[frdiv] bits, f is the fll factor selected by c4[drst_drs] and c4[dmx32] bits. initialization / application information kl04 sub-family reference manual, rev. 3.1, november 2012 358 freescale semiconductor, inc.
this section will include three mode switching examples using an 4 mhz external crystal. 24.5.3.1 example 1: moving from fei to blpe mode: external crystal = 4 mhz, mcgoutclk frequency = 4 mhz in this example, the mcg will move through the proper operational modes from fei to blpe to achieve 4 mhz mcgoutclk frequency from 4 mhz external crystal reference. first, the code sequence will be described. then there is a flowchart that illustrates the sequence. 1. first, fei must transition to fbe mode: a. c2 = 0x1c ? c2[range0] set to 2'b01 because the frequency of 4 mhz is within the high frequency range. ? c2[hgo0] set to 1 to configure the crystal oscillator for high gain operation. ? c2[erefs0] set to 1, because a crystal is being used. b. c1 = 0x90 ? c1[clks] set to 2'b10 to select external reference clock as system clock source ? c1[frdiv] set to 3'b010, or divide-by-128 because 4 mhz / 128 = 31.25 khz which is in the 31.25 khz to 39.0625 khz range required by the fll ? c1[irefs] cleared to 0, selecting the external reference clock and enabling the external oscillator. c. loop until s[oscinit0] is 1, indicating the crystal selected by c2[erefs0] has been initialized. d. loop until s[irefst] is 0, indicating the external reference is the current source for the reference clock. e. loop until s[clkst] is 2'b10, indicating that the external reference clock is selected to feed mcgoutclk. 2. then, transition to blpe: a. set c2[lp] to 1. chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 359
c2 = 0x1c start in fei mode no no no yes yes yes check c1 = 0x40 check check c2 = 0x1e (c2[lp] = 1) s[clkst] = %10? s[irefst] = 0? s[oscinit0] = 1? continue in blpe mode figure 24-12. flowchart of fei to blpe mode transition using a 4 mhz crystal initialization / application information kl04 sub-family reference manual, rev. 3.1, november 2012 360 freescale semiconductor, inc.
24.5.3.2 example 2: moving from blpe to blpi mode: mcgoutclk frequency = 2 mhz in this example, the mcg will move through the proper operational modes from blpe mode with a 4 mhz crystal configured for a 4 mhz mcgoutclk frequency (see previous example) to blpi mode with a 2 mhz mcgoutclk frequency. first, the code sequence will be described. then there is a flowchart that illustrates the sequence. 1. first, blpe must transition to fbe mode: a. clear c2[lp] to 0 here to switch to fbe mode. 2. next, fbe mode transitions into fbi mode: a. c1 = 0x54 ? c1[clks] set to 2'b01 to switch the system clock to the internal reference clock. ? c1[irefs] set to 1 to select the internal reference clock as the reference clock source. ? c1[frdiv] remain unchanged because the reference divider does not affect the internal reference. b. loop until s[irefst] is 1, indicating the internal reference clock has been selected as the reference clock source. c. loop until s[clkst] are 2'b01, indicating that the internal reference clock is selected to feed mcgoutclk. 3. lastly, fbi transitions into blpi mode with ircs selecting fast internal reference clock. a. c2 = 0x03 ? c2[ircs] is 1 ? c2[lp] is 1 ? c2[range0], c2[hgo0], c2[erefs0], c1[irclken], and c1[irefsten] bits are ignored when the c1[irefs] bit is set. they can remain set, or be cleared at this point. b. loop until s[ircst] is 1, indicating the internal reference clock is the fast clock. chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 361
no yes check s[ircst] = 1? no no yes c2 = 0x23 continue in blpi mode yes c1 = 0x64 check s[irefst] = 0? check s[clkst] = %01? c2 = 0x1c (c2[lp] = 0) start in blpe mode figure 24-13. flowchart of blpe to blpi mode transition using an 4 mhz crystal initialization / application information kl04 sub-family reference manual, rev. 3.1, november 2012 362 freescale semiconductor, inc.
24.5.3.3 example 3: moving from blpi to fee mode in this example, the mcg will move through the proper operational modes from blpi mode at a 32 khz mcgoutclk frequency running off the internal reference clock (see previous example) to fee mode using a 4 mhz crystal configured for a 20 mhz mcgoutclk frequency. first, the code sequence will be described. then there is a flowchart that illustrates the sequence. 1. first, blpi must transition to fbi mode. a. c2 = 0x00 ? c2[lp] is 0 2. next, fbi will transition to fee mode. a. c2 = 0x1c ? c2[range0] set to 2'b01 because the frequency of 4 mhz is within the high frequency range. ? c2[hgo0] set to 1 to configure the crystal oscillator for high gain operation. ? c2[erefs0] set to 1, because a crystal is being used. b. c1 = 0x10 ? c1[clks] set to 2'b00 to select the output of the fll as system clock source. ? c1[frdiv] remain at 3'b010, or divide-by-128 for a reference of 4 mhz / 128 = 31.25 khz. ? c1[irefs] cleared to 0, selecting the external reference clock. c. loop until s[oscinit0] is 1, indicating the crystal selected by the c2[erefs0] bit has been initialized. d. loop until s[irefst] is 0, indicating the external reference clock is the current source for the reference clock. e. loop until s[clkst] are 2'b00, indicating that the output of the fll is selected to feed mcgoutclk. f. now, with a 31.25 khz reference frequency, a fixed dco multiplier of 640, mcgoutclk = 31.25 khz * 640 / 1 = 20 mhz. g. at this point, by default, the c4[drst_drs] bits are set to 2'b00 and c4[dmx32] is cleared to 0. if the mcgoutclk frequency of 40 mhz is desired instead, set the c4[drst_drs] bits to 0x01 to switch the fll chapter 24 multipurpose clock generator (mcg) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 363
multiplication factor from 640 to 1280. to return the mcgoutclk frequency to 20 mhz, set c4[drst_drs] bits to 2'b00 again, and the fll multiplication factor will switch back to 640. c1 = 0x10 c2 = 0x00 c2 = 0x1c check check check s[oscinit] = 1 ? continue in fee mode no no no yes yes yes start in blpi mode s[irefst] = 0? s[clkst] = %00? figure 24-14. flowchart of blpi to fee mode transition using an 4 mhz crystal initialization / application information kl04 sub-family reference manual, rev. 3.1, november 2012 364 freescale semiconductor, inc.
chapter 25 oscillator (osc) 25.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the osc module is a crystal oscillator. the module, in conjunction with an external crystal or resonator, generates a reference clock for the mcu. 25.2 features and modes key features of the module are: ? supports 32 khz crystals (low range mode) ? voltage and frequency filtering to guarantee clock frequency and stability ? optionally external input bypass clock from extal signal directly ? one clock for mcu clock system ? two clocks for on-chip peripherals that can work in stop modes functional description describes the module's operation in more detail. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 365
25.3 block diagram the osc module uses a crystal or resonator to generate three filtered oscillator clock signals. three clocks are output from osc module: oscclk for mcu system, oscerclk for on-chip peripherals, and osc32kclk. the oscclk can only work in run mode. oscerclk and osc32kclk can work in low power modes. for the clock source assignments, refer to the clock distribution information of this mcu. refer to the chip configuration chapter for the external reference clock source in this mcu. the following figure shows the block diagram of the osc module. xtal extal xtl_clk cnt_done_4096 osc_clk_out mux 4096 counter osc clock enable stop osc clock selection oscerclk erclken oscclk osc32kclk oscillator circuits e n control and decoding logic erclken erefsten osc_en figure 25-1. osc module block diagram 25.4 osc signal descriptions the following table shows the user-accessible signals available for the osc module. refer to signal multiplexing information for this mcu for more details. block diagram kl04 sub-family reference manual, rev. 3.1, november 2012 366 freescale semiconductor, inc.
table 25-1. osc signal descriptions signal description i/o extal external clock/oscillator input i xtal oscillator output o 25.5 external crystal / resonator connections the connections for a crystal/resonator frequency reference are shown in the following figures. when using low-frequency, low-power mode, the only external component is the crystal or ceramic resonator itself. in the other oscillator modes, load capacitors (c x , c y ) and feedback resistor (r f ) are required. the following table shows all possible connections. table 25-2. external caystal/resonator connections oscillator mode connections low-frequency (32 khz), low-power connection 1 1 low-frequency (32 khz), high-gain connection 2/connection 3 2 high-frequency (3~32 mhz), low-power connection 3 1 high-frequency (3~32 mhz), high-gain connection 3 1. with the low-power mode, the oscillator has the internal feedback resistor r f . therefore, the feedback resistor must not be externally with the connection 3. 2. when the load capacitors (cx, cy) are greater than 30 pf, use connection 3. osc extal crystal or resonator v ss xtal figure 25-2. crystal/ceramic resonator connections - connection 1 chapter 25 oscillator (osc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 367
osc v ss r f crystal or resonator xtal extal figure 25-3. crystal/ceramic resonator connections - connection 2 note connection 1 and connection 2 should use internal capacitors as the load of the oscillator by configuring the cr[scxp] bits. osc v ss c x c y r f crystal or resonator xtal extal figure 25-4. crystal/ceramic resonator connections - connection 3 25.6 external clock connections in external clock mode, the pins can be connected as shown below. note xtal can be used as a gpio when the gpio alternate function is configured for it. external clock connections kl04 sub-family reference manual, rev. 3.1, november 2012 368 freescale semiconductor, inc.
osc v ss clock input i/o xtal extal figure 25-5. external clock connections 25.7 memory map/register definitions some oscillator module register bits are typically incorporated into other peripherals such as mcg or sim. osc memory map/register definition osc memory map absolute address (hex) register name width (in bits) access reset value section/ page 4006_5000 osc control register (osc0_cr) 8 r/w 00h 25.71.1/369 25.71.1 osc control register (osc x _cr) note after osc is enabled and starts generating the clocks, the configurations such as low power and frequency range, must not be changed. address: 4006_5000h base + 0h offset = 4006_5000h bit 7 6 5 4 3 2 1 0 read erclken 0 erefsten 0 sc2p sc4p sc8p sc16p write reset 0 0 0 0 0 0 0 0 osc x _cr field descriptions field description 7 erclken external reference enable enables external reference clock (oscerclk). table continues on the next page... 25.7.1 chapter 25 oscillator (osc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 369
osc x _cr field descriptions (continued) field description 0 external reference clock is inactive. 1 external reference clock is enabled. 6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5 erefsten external reference stop enable controls whether or not the external reference clock (oscerclk) remains enabled when mcu enters stop mode. 0 external reference clock is disabled in stop mode. 1 external reference clock stays enabled in stop mode if erclken is set before entering stop mode. 4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 sc2p oscillator 2 pf capacitor load configure configures the oscillator load. 0 disable the selection. 1 add 2 pf capacitor to the oscillator load. 2 sc4p oscillator 4 pf capacitor load configure configures the oscillator load. 0 disable the selection. 1 add 4 pf capacitor to the oscillator load. 1 sc8p oscillator 8 pf capacitor load configure configures the oscillator load. 0 disable the selection. 1 add 8 pf capacitor to the oscillator load. 0 sc16p oscillator 16 pf capacitor load configure configures the oscillator load. 0 disable the selection. 1 add 16 pf capacitor to the oscillator load. 25.8 functional description this following sections provide functional details of the module. 25.8.1 osc module states the states of the osc module are shown in the following figure. the states and their transitions between each other are described in this section. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 370 freescale semiconductor, inc.
stable off oscclk cnt_done_4096 start-up oscclk requested external clock mode oscillator on, stable oscillator off oscillator on, not yet stable oscillator on osc_clk_out = static osc_clk_out = static osc_clk_out = extal osc_clk_out = xtl_clk not requested && select osc internal clock oscclk requested && select clock from extal signal figure 25-8. osc module state diagram note xtl_clk is the clock generated internally from osc circuits. 25.8.1.1 off the osc enters the off state when the system does not require osc clocks. upon entering this state, xtl_clk is static unless osc is configured to select the clock from the extal pad by clearing the external reference clock selection bit. for details regarding the external reference clock source in this mcu, refer to the chip configuration chapter. the extal and xtal pins are also decoupled from all other oscillator circuitry in this state. the osc module circuitry is configured to draw minimal current. chapter 25 oscillator (osc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 371
25.8.1.2 oscillator start-up the osc enters start-up state when it is configured to generate clocks (internally the osc_en transitions high) using the internal oscillator circuits by setting the external reference clock selection bit. in this state, the osc module is enabled and oscillations are starting up, but have not yet stabilized. when the oscillation amplitude becomes large enough to pass through the input buffer, xtl_clk begins clocking the counter. when the counter reaches 4096 cycles of xtl_clk, the oscillator is considered stable and xtl_clk is passed to the output clock osc_clk_out. 25.8.1.3 oscillator stable the osc enters stable state when it is configured to generate clocks (internally the osc_en transitions high) using the internal oscillator circuits by setting the external reference clock selection bit and the counter reaches 4096 cycles of xtl_clk (when cnt_done_4096 is high). in this state, the osc module is producing a stable output clock on osc_clk_out. its frequency is determined by the external components being used. 25.8.1.4 external clock mode the osc enters external clock state when it is enabled and external reference clock selection bit is cleared. for details regarding external reference clock source in this mcu, refer to the chip configuration chapter. in this state, the osc module is set to buffer (with hysteresis) a clock from extal onto the osc_clk_out. its frequency is determined by the external clock being supplied. 25.8.2 osc module modes the osc is a pierce-type oscillator that supports external crystals or resonators operating over the frequency ranges shown in table 25-7 . these modes assume the following conditions: osc is enabled to generate clocks (osc_en=1), configured to generate clocks internally (mcg_c2[erefs] = 1), and some or one of the other peripherals (mcg, timer, and so on) is configured to use the oscillator output clock (osc_clk_out). table 25-7. oscillator modes mode frequency range low-frequency, low-power (vlp) f osc_lo (1 khz) up to f osc_lo (32.768 khz) functional description kl04 sub-family reference manual, rev. 3.1, november 2012 372 freescale semiconductor, inc.
note for information about low power modes of operation used in this chip and their alignment with some osc modes, refer to the chip's power management details. 25.8.2.1 low-frequency, low-power mode in low-frequency, low-power mode, the oscillator uses a gain control loop to minimize power consumption. as the oscillation amplitude increases, the amplifier current is reduced. this continues until a desired amplitude is achieved at steady-state. this mode provides low pass frequency filtering as well as hysteresis for voltage filtering and converts the output to logic levels. in this mode, the internal capacitors could be used, the internal feedback resistor is connected, and no external resistor should be used. in this mode, the amplifier inputs, gain-control input, and input buffer input are all capacitively coupled for leakage tolerance (not sensitive to the dc level of extal). also in this mode, all external components except for the resonator itself are integrated, which includes the load capacitors and feeback resistor that biases extal. 25.8.3 counter the oscillator output clock (osc_clk_out) is gated off until the counter has detected 4096 cycles of its input clock (xtl_clk). after 4096 cycles are completed, the counter passes xtl_clk onto osc_clk_out. this counting time-out is used to guarantee output clock stability. 25.8.4 reference clock pin requirements the osc module requires use of both the extal and xtal pins to generate an output clock in oscillator mode, but requires only the extal pin in external clock mode. the extal and xtal pins are available for i/o. for the implementation of these pins on this device, refer to the signal multiplexing chapter. chapter 25 oscillator (osc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 373
25.9 reset there is no reset state associated with the osc module. the counter logic is reset when the osc is not configured to generate clocks. there are no sources of reset requests for the osc module. 25.10 low power modes operation when the mcu enters stop modes, the osc is functional depending on erclken and erefsetn bit settings. if both these bits are set, the osc is in operation. in low leakage stop (lls) modes, the osc holds all register settings. if erclken and erefsten bits are set before entry to low leakage stop modes, the osc is still functional in these modes. after waking up from very low leakage stop (vllsx) modes, all osc register bits are reset and initialization is required through software. 25.11 interrupts the osc module does not generate any interrupts. reset kl04 sub-family reference manual, rev. 3.1, november 2012 374 freescale semiconductor, inc.
chapter 26 flash memory controller (fmc) 26.1 introduction the flash memory controller (fmc) is a memory acceleration unit that provides: ? an interface between bus masters and the 32-bit program flash memory. ? a buffer and a cache that can accelerate program flash memory data transfers. 26.1.1 overview the flash memory controller manages the interface between bus masters and the 32-bit program flash memory. the fmc receives status information detailing the configuration of the flash memory and uses this information to ensure a proper interface. the fmc supports 8-bit, 16-bit, and 32-bit read operations from the program flash memory. a write operation to program flash memory results in a bus error. in addition, the fmc provides two separate mechanisms for accelerating the interface between bus masters and program flash memory. a 32-bit speculation buffer can prefetch the next 32-bit flash memory location, and a 4-way, 4-set program flash memory cache can store previously accessed program flash memory data for quick access times. 26.1.2 features the fmc's features include: ? interface between bus masters and the 32-bit program flash memory: ? 8-bit, 16-bit, and 32-bit read operations to nonvolatile flash memory. ? acceleration of data transfer from the program flash memory to the device: kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 375
? 32-bit prefetch speculation buffer for program flash accesses with controls for instruction/data access ? 4-way, 4-set, 32-bit line size program flash memory cache for a total of sixteen 32-bit entries with invalidation control 26.2 modes of operation the fmc operates only when a bus master accesses the program flash memory. in terms of chip power modes: ? the fmc operates only in run and wait modes, including vlpr and vlpw modes. ? for any power mode where the program flash memory cannot be accessed, the fmc is disabled. 26.3 external signal description the fmc has no external (off-chip) signals. 26.4 memory map and register descriptions the mcm's programming model provides control and configuration of the fmc's features. for details, see the description of the mcm's platform control register (placr). 26.5 functional description the fmc is a flash acceleration unit with flexible buffers for user configuration. besides managing the interface between bus masters and the program flash memory, the fmc can be used to customize the program flash memory cache and buffer to provide single-cycle system clock data access times. whenever a hit occurs for the prefetch speculation buffer or the cache (when enabled), the requested data is transferred within a single system clock. upon system reset, the fmc is configured as follows: ? flash cache is enabled ? instruction speculation and caching are enabled modes of operation kl04 sub-family reference manual, rev. 3.1, november 2012 376 freescale semiconductor, inc.
? data speculation is disabled ? data caching is enabled though the default configuration provides flash acceleration, advanced users may desire to customize the fmc buffer configurations to maximize throughput for their use cases. for example, the user may adjust the controls to enable buffering per access type (data or instruction). note when reconfiguring the fmc, do not program the control and configuration inputs to the fmc while the program flash memory is being accessed. instead, change them with a routine executing from ram in supervisor mode. chapter 26 flash memory controller (fmc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 377
functional description kl04 sub-family reference manual, rev. 3.1, november 2012 378 freescale semiconductor, inc.
chapter 27 flash memory module (ftfa) 27.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the flash memory module includes the following accessible memory regions: ? program flash memory for vector space and code store flash memory is ideal for single-supply applications, permitting in-the-field erase and reprogramming operations without the need for any external high voltage power sources. the flash memory module includes a memory controller that executes commands to modify flash memory contents. an erased bit reads '1' and a programmed bit reads '0'. the programming operation is unidirectional; it can only move bits from the '1' state (erased) to the '0' state (programmed). only the erase operation restores bits from '0' to '1'; bits cannot be programmed from a '0' to a '1'. caution a flash memory location must be in the erased state before being programmed. cumulative programming of bits (back-to- back program operations without an intervening erase) within a flash memory location is not allowed. re-programming of existing 0s to 0 is not allowed as this overstresses the device. the standard shipping condition for flash memory is erased with security disabled. data loss over time may occur due to degradation of the erased ('1') states and/or programmed ('0') states. therefore, it is recommended that each flash block or sector be re-erased immediately prior to factory programming to ensure that the full data retention capability is achieved. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 379
27.1.1 features the flash memory module includes the following features. note see the device's chip configuration details for the exact amount of flash memory available on your device. 27.1.1.1 program flash memory features ? sector size of 1 kbyte ? program flash protection scheme prevents accidental program or erase of stored data ? automated, built-in, program and erase algorithms with verify 27.1.1.2 other flash memory module features ? internal high-voltage supply generator for flash memory program and erase operations ? optional interrupt generation upon flash command completion ? supports mcu security mechanisms which prevent unauthorized access to the flash memory contents 27.1.2 block diagram the block diagram of the flash memory module is shown in the following figure. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 380 freescale semiconductor, inc.
program flash 0 to mcu's flash controller interrupt control registers status registers register access memory controller figure 27-1. flash block diagram 27.1.3 glossary command write sequence a series of mcu writes to the flash fccob register group that initiates and controls the execution of flash algorithms that are built into the flash memory module. endurance the number of times that a flash memory location can be erased and reprogrammed. fccob (flash common command object) a group of flash registers that are used to pass command, address, data, and any associated parameters to the memory controller in the flash memory module. flash block a macro within the flash memory module which provides the nonvolatile memory storage. flash memory module all flash blocks plus a flash management unit providing high-level control and an interface to mcu buses. ifr nonvolatile information register found in each flash block, separate from the main memory array. nvm nonvolatile memory. a memory technology that maintains stored data during power-off. the flash array is an nvm using nor-type flash memory technology. nvm normal mode an nvm mode that provides basic user access to flash memory module resources. the cpu or other bus masters initiate flash program and erase operations (or other flash commands) using writes to the fccob register group in the flash memory module. chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 381
nvm special mode an nvm mode enabling external, off-chip access to the memory resources in the flash memory module. a reduced flash command set is available when the mcu is secured. see the chip configuration details for information on when this mode is used. longword 32 bits of data with an aligned longword having byte-address[1:0] = 00. word 16 bits of data with an aligned word having byte-address[0] = 0. program flash the program flash memory provides nonvolatile storage for vectors and code store. program flash sector the smallest portion of the program flash memory (consecutive addresses) that can be erased. retention the length of time that data can be kept in the nvm without experiencing errors upon readout. since erased (1) states are subject to degradation just like programmed (0) states, the data retention limit may be reached from the last erase operation (not from the programming time). rww read-while-write. the ability to simultaneously read from one memory resource while commanded operations are active in another memory resource. secure an mcu state conveyed to the flash memory module as described in the chip configuration details for this device. in the secure state, reading and changing nvm contents is restricted. 27.2 external signal description the flash memory module contains no signals that connect off-chip. 27.3 memory map and registers this section describes the memory map and registers for the flash memory module. data read from unimplemented memory space in the flash memory module is undefined. writes to unimplemented or reserved memory space (registers) in the flash memory module are ignored. external signal description kl04 sub-family reference manual, rev. 3.1, november 2012 382 freescale semiconductor, inc.
27.3.1 flash configuration field description the program flash memory contains a 16-byte flash configuration field that stores default protection settings (loaded on reset) and security information that allows the mcu to restrict access to the flash memory module. flash configuration field byte address size (bytes) field description 0x0_0400 - 0x0_0407 8 backdoor comparison key. refer to verify backdoor access key command and unsecuring the chip using backdoor key access . 0x0_0408 - 0x0_040b 4 program flash protection bytes. refer to the description of the program flash protection registers (fprot0-3). 0x0_040f 1 reserved 0x0_040e 1 reserved 0x0_040d 1 flash nonvolatile option byte. refer to the description of the flash option register (fopt). 0x0_040c 1 flash security byte. refer to the description of the flash security register (fsec). 27.3.2 program flash ifr map the program flash ifr is nonvolatile information memory that can be read freely, but the user has no erase and limited program capabilities (see the read once, program once, and read resource commands in read once command , program once command and read resource command ). the contents of the program flash ifr are summarized in the following table and further described in the subsequent paragraphs. the program flash ifr is located within the program flash 0 memory block. address range size (bytes) field description 0x00 C 0xbf 192 reserved 0xc0 C 0xff 64 program once field 27.3.2.1 program once field the program once field in the program flash ifr provides 64 bytes of user data storage separate from the program flash main array. the user can program the program once field one time only as there is no program flash ifr erase mechanism available to the chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 383
user. the program once field can be read any number of times. this section of the program flash ifr is accessed in 4-byte records using the read once and program once commands (see read once command and program once command ). 27.3.3 register descriptions the flash memory module contains a set of memory-mapped control and status registers. note while a command is running (fstat[ccif]=0), register writes are not accepted to any register except fcnfg and fstat. the no-write rule is relaxed during the start-up reset sequence, prior to the initial rise of ccif. during this initialization period the user may write any register. all register writes are also disabled (except for registers fcnfg and fstat) whenever an erase suspend request is active (fcnfg[erssusp]=1). ftfa memory map absolute address (hex) register name width (in bits) access reset value section/ page 4002_0000 flash status register (ftfa_fstat) 8 r/w 00h 27.33.1/385 4002_0001 flash configuration register (ftfa_fcnfg) 8 r/w 00h 27.33.2/386 4002_0002 flash security register (ftfa_fsec) 8 r undefined 27.33.3/388 4002_0003 flash option register (ftfa_fopt) 8 r undefined 27.33.4/389 4002_0004 flash common command object registers (ftfa_fccob3) 8 r/w 00h 27.33.5/390 4002_0005 flash common command object registers (ftfa_fccob2) 8 r/w 00h 27.33.5/390 4002_0006 flash common command object registers (ftfa_fccob1) 8 r/w 00h 27.33.5/390 4002_0007 flash common command object registers (ftfa_fccob0) 8 r/w 00h 27.33.5/390 4002_0008 flash common command object registers (ftfa_fccob7) 8 r/w 00h 27.33.5/390 4002_0009 flash common command object registers (ftfa_fccob6) 8 r/w 00h 27.33.5/390 4002_000a flash common command object registers (ftfa_fccob5) 8 r/w 00h 27.33.5/390 4002_000b flash common command object registers (ftfa_fccob4) 8 r/w 00h 27.33.5/390 4002_000c flash common command object registers (ftfa_fccobb) 8 r/w 00h 27.33.5/390 table continues on the next page... memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 384 freescale semiconductor, inc.
ftfa memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page 4002_000d flash common command object registers (ftfa_fccoba) 8 r/w 00h 27.33.5/390 4002_000e flash common command object registers (ftfa_fccob9) 8 r/w 00h 27.33.5/390 4002_000f flash common command object registers (ftfa_fccob8) 8 r/w 00h 27.33.5/390 4002_0010 program flash protection registers (ftfa_fprot3) 8 r/w undefined 27.33.6/391 4002_0011 program flash protection registers (ftfa_fprot2) 8 r/w undefined 27.33.6/391 4002_0012 program flash protection registers (ftfa_fprot1) 8 r/w undefined 27.33.6/391 4002_0013 program flash protection registers (ftfa_fprot0) 8 r/w undefined 27.33.6/391 27.33.1 flash status register (ftfa_fstat) the fstat register reports the operational status of the flash memory module. the ccif, rdcolerr, accerr, and fpviol bits are readable and writable. the mgstat0 bit is read only. the unassigned bits read 0 and are not writable. note when set, the access error (accerr) and flash protection violation (fpviol) bits in this register prevent the launch of any more commands until the flag is cleared (by writing a one to it). address: 4002_0000h base + 0h offset = 4002_0000h bit 7 6 5 4 3 2 1 0 read ccif rdcolerr accerr fpviol 0 mgstat0 write w1c w1c w1c w1c reset 0 0 0 0 0 0 0 0 ftfa_fstat field descriptions field description 7 ccif command complete interrupt flag the ccif flag indicates that a flash command has completed. the ccif flag is cleared by writing a 1 to ccif to launch a command, and ccif stays low until command completion or command violation. the ccif bit is reset to 0 but is set to 1 by the memory controller at the end of the reset initialization sequence. depending on how quickly the read occurs after reset release, the user may or may not see the 0 hardware reset value. table continues on the next page... chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 385
ftfa_fstat field descriptions (continued) field description 0 flash command in progress 1 flash command has completed 6 rdcolerr flash read collision error flag the rdcolerr error bit indicates that the mcu attempted a read from a flash memory resource that was being manipulated by a flash command (ccif=0). any simultaneous access is detected as a collision error by the block arbitration logic. the read data in this case cannot be guaranteed. the rdcolerr bit is cleared by writing a 1 to it. writing a 0 to rdcolerr has no effect. 0 no collision error detected 1 collision error detected 5 accerr flash access error flag the accerr error bit indicates an illegal access has occurred to a flash memory resource caused by a violation of the command write sequence or issuing an illegal flash command. while accerr is set, the ccif flag cannot be cleared to launch a command. the accerr bit is cleared by writing a 1 to it. writing a 0 to the accerr bit has no effect. 0 no access error detected 1 access error detected 4 fpviol flash protection violation flag the fpviol error bit indicates an attempt was made to program or erase an address in a protected area of program flash memory during a command write sequence . while fpviol is set, the ccif flag cannot be cleared to launch a command. the fpviol bit is cleared by writing a 1 to it. writing a 0 to the fpviol bit has no effect. 0 no protection violation detected 1 protection violation detected 3C1 reserved this field is reserved. this read-only field is reserved and always has the value 0. 0 mgstat0 memory controller command completion status flag the mgstat0 status flag is set if an error is detected during execution of a flash command or during the flash reset sequence. as a status flag, this bit cannot (and need not) be cleared by the user like the other error flags in this register. the value of the mgstat0 bit for "command-n" is valid only at the end of the "command-n" execution when ccif=1 and before the next command has been launched. at some point during the execution of "command-n+1," the previous result is discarded and any previous error is cleared. 27.33.2 flash configuration register (ftfa_fcnfg) this register provides information on the current functional state of the flash memory module. the erase control bits (ersareq and erssusp) have write restrictions. the unassigned bits read as noted and are not writable. memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 386 freescale semiconductor, inc.
address: 4002_0000h base + 1h offset = 4002_0001h bit 7 6 5 4 3 2 1 0 read ccie rdcollie ersareq erssusp 0 0 0 0 write reset 0 0 0 0 0 0 0 0 ftfa_fcnfg field descriptions field description 7 ccie command complete interrupt enable the ccie bit controls interrupt generation when a flash command completes. 0 command complete interrupt disabled 1 command complete interrupt enabled. an interrupt request is generated whenever the fstat[ccif] flag is set. 6 rdcollie read collision error interrupt enable the rdcollie bit controls interrupt generation when a flash memory read collision error occurs. 0 read collision error interrupt disabled 1 read collision error interrupt enabled. an interrupt request is generated whenever a flash memory read collision error is detected (see the description of fstat[rdcolerr]). 5 ersareq erase all request this bit issues a request to the memory controller to execute the erase all blocks command and release security. ersareq is not directly writable but is under indirect user control. refer to the device's chip configuration details on how to request this command. the ersareq bit sets when an erase all request is triggered external to the flash memory module and ccif is set (no command is currently being executed). ersareq is cleared by the flash memory module when the operation completes. 0 no request or request complete 1 request to: 1. run the erase all blocks command, 2. verify the erased state, 3. program the security byte in the flash configuration field to the unsecure state, and 4. release mcu security by setting the fsec[sec] field to the unsecure state. 4 erssusp erase suspend the erssusp bit allows the user to suspend (interrupt) the erase flash sector command while it is executing. 0 no suspend requested 1 suspend the current erase flash sector command execution. 3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 reserved this field is reserved. this read-only field is reserved and always has the value 0. 0 reserved this field is reserved. this read-only field is reserved and always has the value 0. chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 387
27.33.3 flash security register (ftfa_fsec) this read-only register holds all bits associated with the security of the mcu and flash memory module. during the reset sequence, the register is loaded with the contents of the flash security byte in the flash configuration field located in program flash memory. the flash basis for the values is signified by x in the reset value. address: 4002_0000h base + 2h offset = 4002_0002h bit 7 6 5 4 3 2 1 0 read keyen meen fslacc sec write reset x* x* x* x* x* x* x* x* * notes: x = undefined at reset. ? ftfa_fsec field descriptions field description 7C6 keyen backdoor key security enable these bits enable and disable backdoor key access to the flash memory module. 00 backdoor key access disabled 01 backdoor key access disabled (preferred keyen state to disable backdoor key access) 10 backdoor key access enabled 11 backdoor key access disabled 5C4 meen mass erase enable bits enables and disables mass erase capability of the flash memory module. the state of the meen bits is only relevant when the sec bits are set to secure outside of nvm normal mode. when the sec field is set to unsecure, the meen setting does not matter. 00 mass erase is enabled 01 mass erase is enabled 10 mass erase is disabled 11 mass erase is enabled 3C2 fslacc freescale failure analysis access code these bits enable or disable access to the flash memory contents during returned part failure analysis at freescale. when sec is secure and fslacc is denied, access to the program flash contents is denied and any failure analysis performed by freescale factory test must begin with a full erase to unsecure the part. when access is granted (sec is unsecure, or sec is secure and fslacc is granted), freescale factory testing has visibility of the current flash contents. the state of the fslacc bits is only relevant when the sec bits are set to secure. when the sec field is set to unsecure, the fslacc setting does not matter. table continues on the next page... memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 388 freescale semiconductor, inc.
ftfa_fsec field descriptions (continued) field description 00 freescale factory access granted 01 freescale factory access denied 10 freescale factory access denied 11 freescale factory access granted 1C0 sec flash security these bits define the security state of the mcu. in the secure state, the mcu limits access to flash memory module resources. the limitations are defined per device and are detailed in the chip configuration details. if the flash memory module is unsecured using backdoor key access, the sec bits are forced to 10b. 00 mcu security status is secure 01 mcu security status is secure 10 mcu security status is unsecure (the standard shipping condition of the flash memory module is unsecure.) 11 mcu security status is secure 27.33.4 flash option register (ftfa_fopt) the flash option register allows the mcu to customize its operations by examining the state of these read-only bits, which are loaded from nvm at reset. the function of the bits is defined in the device's chip configuration details. all bits in the register are read-only . during the reset sequence, the register is loaded from the flash nonvolatile option byte in the flash configuration field located in program flash memory. the flash basis for the values is signified by x in the reset value. address: 4002_0000h base + 3h offset = 4002_0003h bit 7 6 5 4 3 2 1 0 read opt write reset x* x* x* x* x* x* x* x* * notes: x = undefined at reset. ? ftfa_fopt field descriptions field description 7C0 opt nonvolatile option these bits are loaded from flash to this register at reset. refer to the device's chip configuration details for the definition and use of these bits. chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 389
27.33.5 flash common command object registers (ftfa_fccob n ) the fccob register group provides 12 bytes for command codes and parameters. the individual bytes within the set append a 0-b hex identifier to the fccob register name: fccob0, fccob1, ..., fccobb. address: 4002_0000h base + 4h offset + (1d i), where i=0d to 11d bit 7 6 5 4 3 2 1 0 read ccobn write reset 0 0 0 0 0 0 0 0 ftfa_fccob n field descriptions field description 7C0 ccobn the fccob register provides a command code and relevant parameters to the memory controller. the individual registers that compose the fccob data set can be written in any order, but you must provide all needed values, which vary from command to command. first, set up all required fccob fields and then initiate the commands execution by writing a 1 to the fstat[ccif] bit. this clears the ccif bit, which locks all fccob parameter fields and they cannot be changed by the user until the command completes (ccif returns to 1). no command buffering or queueing is provided; the next command can be loaded only after the current command completes. some commands return information to the fccob registers. any values returned to fccob are available for reading after the fstat[ccif] flag returns to 1 by the memory controller. the following table shows a generic flash command format. the first fccob register, fccob0, always contains the command code. this 8-bit value defines the command to be executed. the command code is followed by the parameters required for this specific flash command, typically an address and/or data values. note: the command parameter table is written in terms of fccob number (which is equivalent to the byte number). this number is a reference to the fccob register name and is not the register address. fccob number typical command parameter contents [7:0] 0 fcmd (a code that defines the flash command) 1 flash address [23:16] 2 flash address [15:8] 3 flash address [7:0] 4 data byte 0 5 data byte 1 6 data byte 2 7 data byte 3 8 data byte 4 9 data byte 5 memory map and registers kl04 sub-family reference manual, rev. 3.1, november 2012 390 freescale semiconductor, inc.
ftfa_fccob n field descriptions (continued) field description fccob number typical command parameter contents [7:0] a data byte 6 b data byte 7 fccob endianness and multi-byte access : the fccob register group uses a big endian addressing convention. for all command parameter fields larger than 1 byte, the most significant data resides in the lowest fccob register number. the fccob register group may be read and written as individual bytes, aligned words (2 bytes) or aligned longwords (4 bytes). 27.33.6 program flash protection registers (ftfa_fprot n ) the fprot registers define which logical program flash regions are protected from program and erase operations. protected flash regions cannot have their content changed; that is, these regions cannot be programmed and cannot be erased by any flash command. unprotected regions can be changed by program and erase operations. the four fprot registers allow up to 32 protectable regions. each bit protects a 1/32 region of the program flash memory except for memory configurations with less than 32 kbytes of program flash where each assigned bit protects 1 kbyte . for configurations with 24 kbytes of program flash memory or less, fprot0 is not used. for configurations with 16 kbytes of program flash memory or less, fprot1 is not used. for configurations with 8 kbytes of program flash memory, fprot2 is not used. the bitfields are defined in each register as follows: program flash protection register program flash protection bits fprot0 prot[31:24] fprot1 prot[23:16] fprot2 prot[15:8] fprot3 prot[7:0] during the reset sequence, the fprot registers are loaded with the contents of the program flash protection bytes in the flash configuration field as indicated in the following table. program flash protection register flash configuration field offset address fprot0 0x000b fprot1 0x000a table continues on the next page... chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 391
program flash protection register flash configuration field offset address fprot2 0x0009 fprot3 0x0008 to change the program flash protection that is loaded during the reset sequence, unprotect the sector of program flash memory that contains the flash configuration field. then, reprogram the program flash protection byte. address: 4002_0000h base + 10h offset + (1d i), where i=0d to 3d bit 7 6 5 4 3 2 1 0 read prot write reset x* x* x* x* x* x* x* x* * notes: x = undefined at reset. ? ftfa_fprot n field descriptions field description 7C0 prot program flash region protect each program flash region can be protected from program and erase operations by setting the associated prot bit. in nvm normal mode: the protection can only be increased, meaning that currently unprotected memory can be protected, but currently protected memory cannot be unprotected. since unprotected regions are marked with a 1 and protected regions use a 0, only writes changing 1s to 0s are accepted. this 1-to-0 transition check is performed on a bit-by-bit basis. those fprot bits with 1-to-0 transitions are accepted while all bits with 0-to-1 transitions are ignored. in nvm special mode: all bits of fprot are writable without restriction. unprotected areas can be protected and protected areas can be unprotected. restriction: the user must never write to any fprot register while a command is running (ccif=0). trying to alter data in any protected area in the program flash memory results in a protection violation error and sets the fstat[fpviol] bit. a full block erase of a program flash block is not possible if it contains any protected region. each bit in the 32-bit protection register represents 1/32 of the total program flash except for configurations where program flash memory is less than 32 kbytes. for configurations with less than 32 kbytes of program flash memory, each assigned bit represents 1 kbyte. 0 program flash region is protected. 1 program flash region is not protected 27.4 functional description the following sections describe functional details of the flash memory module. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 392 freescale semiconductor, inc.
27.4.1 flash protection individual regions within the flash memory can be protected from program and erase operations. protection is controlled by the following registers: ? fprot n four registers that protect 32 regions of the program flash memory as shown in the following figure program flash size / 32 program flash size / 32 program flash size / 32 program flash size / 32 program flash size / 32 program flash size / 32 program flash size / 32 fprot3[prot0] 0x0_0000 fprot3[prot1] fprot3[prot2] fprot3[prot3] fprot0[prot29] fprot0[prot31] fprot0[prot30] program flash last program flash address figure 27-24. program flash protection 27.4.2 interrupts the flash memory module can generate interrupt requests to the mcu upon the occurrence of various flash events. these interrupt events and their associated status and control bits are shown in the following table. table 27-24. flash interrupt sources flash event readable status bit interrupt enable bit flash command complete fstat[ccif] fcnfg[ccie] flash read collision error fstat[rdcolerr] fcnfg[rdcollie] chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 393
note vector addresses and their relative interrupt priority are determined at the mcu level. some devices also generate a bus error response as a result of a read collision error event. see the chip configuration information to determine if a bus error response is also supported. 27.4.3 flash operation in low-power modes 27.4.3.1 wait mode when the mcu enters wait mode, the flash memory module is not affected. the flash memory module can recover the mcu from wait via the command complete interrupt (see interrupts ). 27.4.3.2 stop mode when the mcu requests stop mode, if a flash command is active (ccif = 0) the command execution completes before the mcu is allowed to enter stop mode. caution the mcu should never enter stop mode while any flash command is running (ccif = 0). note while the mcu is in very-low-power modes (vlpr, vlpw, vlps), the flash memory module does not accept flash commands. 27.4.4 functional modes of operation the flash memory module has two operating modes: nvm normal and nvm special. the operating mode affects the command set availability (see table 27-25 ). refer to the chip configuration details of this device for how to activate each mode. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 394 freescale semiconductor, inc.
27.4.5 flash reads and ignored writes the flash memory module requires only the flash address to execute a flash memory read. the mcu must not read from the flash memory while commands are running (as evidenced by ccif=0) on that block. read data cannot be guaranteed from a flash block while any command is processing within that block. the block arbitration logic detects any simultaneous access and reports this as a read collision error (see the fstat[rdcolerr] bit). 27.4.6 read while write (rww) the following simultaneous accesses are not allowed: ? reading from program flash memory space while a flash command is active (ccif=0). 27.4.7 flash program and erase all flash functions except read require the user to setup and launch a flash command through a series of peripheral bus writes. the user cannot initiate any further flash commands until notified that the current command has completed. the flash command structure and operation are detailed in flash command operations . 27.4.8 flash command operations flash command operations are typically used to modify flash memory contents. the next sections describe: ? the command write sequence used to set flash command parameters and launch execution ? a description of all flash commands available chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 395
27.4.8.1 command write sequence flash commands are specified using a command write sequence illustrated in figure 27-25 . the flash memory module performs various checks on the command (fccob) content and continues with command execution if all requirements are fulfilled. before launching a command, the accerr and fpviol bits in the fstat register must be zero and the ccif flag must read 1 to verify that any previous command has completed. if ccif is zero, the previous command execution is still active, a new command write sequence cannot be started, and all writes to the fccob registers are ignored. 27.4.8.1.1 load the fccob registers the user must load the fccob registers with all parameters required by the desired flash command. the individual registers that make up the fccob data set can be written in any order. 27.4.8.1.2 launch the command by clearing ccif once all relevant command parameters have been loaded, the user launches the command by clearing the fstat[ccif] bit by writing a '1' to it. the ccif flag remains zero until the flash command completes. the fstat register contains a blocking mechanism that prevents a new command from launching (can't clear ccif) if the previous command resulted in an access error (fstat[accerr]=1) or a protection violation (fstat[fpviol]=1). in error scenarios, two writes to fstat are required to initiate the next command: the first write clears the error flags, the second write clears ccif. 27.4.8.1.3 command execution and error reporting the command processing has several steps: 1. the flash memory module reads the command code and performs a series of parameter checks and protection checks, if applicable, which are unique to each command. if the parameter check fails, the fstat[accerr] (access error) flag is set. accerr reports invalid instruction codes and out-of bounds addresses. usually, access errors suggest that the command was not set-up with valid parameters in the fccob register group. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 396 freescale semiconductor, inc.
program and erase commands also check the address to determine if the operation is requested to execute on protected areas. if the protection check fails, the fstat[fpviol] (protection error) flag is set. command processing never proceeds to execution when the parameter or protection step fails. instead, command processing is terminated after setting the fstat[ccif] bit. 2. if the parameter and protection checks pass, the command proceeds to execution. run-time errors, such as failure to erase verify, may occur during the execution phase. run-time errors are reported in the fstat[mgstat0] bit. a command may have access errors, protection errors, and run-time errors, but the run-time errors are not seen until all access and protection errors have been corrected. 3. command execution results, if applicable, are reported back to the user via the fccob and fstat registers. 4. the flash memory module sets the fstat[ccif] bit signifying that the command has completed. the flow for a generic command write sequence is illustrated in the following figure. chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 397
clear the ccif to launch the command write 0x80 to fstat register clear the old errors access error and protection violation check fccob accerr/ fpviol set? exit write to the fccob registers to load the required command parameter. more parameters? availability check results from previous command read: fstat register write 0x30 to fstat register no yes no yes previous command complete? no ccif = 1? yes start figure 27-25. generic flash command write sequence flowchart 27.4.8.2 flash commands the following table summarizes the function of all flash commands. fcmd command program flash function 0x01 read 1s section verify that a given number of program flash locations from a starting address are erased. 0x02 program check tests previously-programmed locations at margin read levels. 0x03 read resource ifr, id read 4 bytes from program flash ifr or version id. 0x06 program longword program 4 bytes in a program flash block. table continues on the next page... functional description kl04 sub-family reference manual, rev. 3.1, november 2012 398 freescale semiconductor, inc.
fcmd command program flash function 0x09 erase flash sector erase all bytes in a program flash sector. 0x40 read 1s all blocks verify that the program flash block is erased then release mcu security. 0x41 read once ifr read 4 bytes of a dedicated 64 byte field in the program flash 0 ifr. 0x43 program once ifr one-time program of 4 bytes of a dedicated 64-byte field in the program flash 0 ifr. 0x44 erase all blocks erase the program flash block, verify-erase and release mcu security. note: an erase is only possible when all memory locations are unprotected. 0x45 verify backdoor access key release mcu security after comparing a set of user- supplied security keys to those stored in the program flash. 27.4.8.3 flash commands by mode the following table shows the flash commands that can be executed in each flash operating mode. table 27-25. flash commands by mode fcmd command nvm normal nvm special unsecure secure meen=10 unsecure secure meen=10 0x01 read 1s section 0x02 program check 0x03 read resource 0x06 program longword 0x09 erase flash sector 0x40 read 1s all blocks 0x41 read once 0x43 program once 0x44 erase all blocks 0x45 verify backdoor access key chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 399
27.4.9 margin read commands the read-1s commands (read 1s all blocks and read 1s section) and the program check command have a margin choice parameter that allows the user to apply non- standard read reference levels to the program flash array reads performed by these commands. using the preset 'user' and 'factory' margin levels, these commands perform their associated read operations at tighter tolerances than a 'normal' read. these non- standard read levels are applied only during the command execution. all simple (uncommanded) flash array reads to the mcu always use the standard, un-margined, read reference level. only the 'normal' read level should be employed during normal flash usage. the non- standard, 'user' and 'factory' margin levels should be employed only in special cases. they can be used during special diagnostic routines to gain confidence that the device is not suffering from the end-of-life data loss customary of flash memory devices. erased ('1') and programmed ('0') bit states can degrade due to elapsed time and data cycling (number of times a bit is erased and re-programmed). the lifetime of the erased states is relative to the last erase operation. the lifetime of the programmed states is measured from the last program time. the 'user' and 'factory' levels become, in effect, a minimum safety margin; i.e. if the reads pass at the tighter tolerances of the 'user' and 'factory' margins, then the 'normal' reads have at least this much safety margin before they experience data loss. the 'user' margin is a small delta to the normal read reference level. 'user' margin levels can be employed to check that flash memory contents have adequate margin for normal level read operations. if unexpected read results are encountered when checking flash memory contents at the 'user' margin levels, loss of information might soon occur during 'normal' readout. the 'factory' margin is a bigger deviation from the norm, a more stringent read criteria that should only be attempted immediately (or very soon) after completion of an erase or program command, early in the cycling life. 'factory' margin levels can be used to check that flash memory contents have adequate margin for long-term data retention at the normal level setting. if unexpected results are encountered when checking flash memory contents at 'factory' margin levels, the flash memory contents should be erased and reprogrammed. caution factory margin levels must only be used during verify of the initial factory programming. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 400 freescale semiconductor, inc.
27.4.10 flash command description this section describes all flash commands that can be launched by a command write sequence. the flash memory module sets the fstat[accerr] bit and aborts the command execution if any of the following illegal conditions occur: ? there is an unrecognized command code in the fccob fcmd field. ? there is an error in a fccob field for the specific commands. refer to the error handling table provided for each command. ensure that the accerr and fpviol bits in the fstat register are cleared prior to starting the command write sequence. as described in launch the command by clearing ccif , a new command cannot be launched while these error flags are set. do not attempt to read a flash block while the flash memory module is running a command (ccif = 0) on that same block. the flash memory module may return invalid data to the mcu with the collision error flag (fstat[rdcolerr]) set. caution flash data must be in the erased state before being programmed. cumulative programming of bits (adding more zeros) is not allowed. 27.4.10.1 read 1s section command the read 1s section command checks if a section of program flash memory is erased to the specified read margin level. the read 1s section command defines the starting address and the number of longwords to be verified. table 27-26. read 1s section command fccob requirements fccob number fccob contents [7:0] 0 0x01 (rd1sec) 1 flash address [23:16] of the first longword to be verified 2 flash address [15:8] of the first longword to be verified 3 flash address [7:0] 1 of the first longword to be verified 4 number of longwords to be verified [15:8] 5 number of longwords to be verified [7:0] 6 read-1 margin choice 1. must be longword aligned (flash address [1:0] = 00). chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 401
upon clearing ccif to launch the read 1s section command, the flash memory module sets the read margin for 1s according to table 27-27 and then reads all locations within the specified section of flash memory. if the flash memory module fails to read all 1s (i.e. the flash section is not erased), the fstat[mgstat0] bit is set. the ccif flag sets after the read 1s section operation completes. table 27-27. margin level choices for read 1s section read margin choice margin level description 0x00 use the 'normal' read level for 1s 0x01 apply the 'user' margin to the normal read-1 level 0x02 apply the 'factory' margin to the normal read-1 level table 27-28. read 1s section command error handling error condition error bit command not available in current mode/security fstat[accerr] an invalid margin code is supplied fstat[accerr] an invalid flash address is supplied fstat[accerr] flash address is not longword aligned fstat[accerr] the requested section crosses a flash block boundary fstat[accerr] the requested number of longwords is zero fstat[accerr] read-1s fails fstat[mgstat0] 27.4.10.2 program check command the program check command tests a previously programmed program flash longword to see if it reads correctly at the specified margin level. table 27-29. program check command fccob requirements fccob number fccob contents [7:0] 0 0x02 (pgmchk) 1 flash address [23:16] 2 flash address [15:8] 3 flash address [7:0] 1 4 margin choice 8 byte 0 expected data 9 byte 1 expected data a byte 2 expected data b byte 3 expected data 1. must be longword aligned (flash address [1:0] = 00). functional description kl04 sub-family reference manual, rev. 3.1, november 2012 402 freescale semiconductor, inc.
upon clearing ccif to launch the program check command, the flash memory module sets the read margin for 1s according to table 27-30 , reads the specified longword, and compares the actual read data to the expected data provided by the fccob. if the comparison at margin-1 fails, the fstat[mgstat0] bit is set. the flash memory module then sets the read margin for 0s, re-reads, and compares again. if the comparison at margin-0 fails, the fstat[mgstat0] bit is set. the ccif flag is set after the program check operation completes. the supplied address must be longword aligned (the lowest two bits of the byte address must be 00): ? byte 3 data is written to the supplied byte address ('start'), ? byte 2 data is programmed to byte address start+0b01, ? byte 1 data is programmed to byte address start+0b10, ? byte 0 data is programmed to byte address start+0b11. note see the description of margin reads, margin read commands table 27-30. margin level choices for program check read margin choice margin level description 0x01 read at 'user' margin-1 and 'user' margin-0 0x02 read at 'factory' margin-1 and 'factory' margin-0 table 27-31. program check command error handling error condition error bit command not available in current mode/security fstat[accerr] an invalid flash address is supplied fstat[accerr] flash address is not longword aligned fstat[accerr] an invalid margin choice is supplied fstat[accerr] either of the margin reads does not match the expected data fstat[mgstat0] 27.4.10.3 read resource command the read resource command allows the user to read data from special-purpose memory resources located within the flash memory module. the special-purpose memory resources available include program flash ifr space and the version id field. each resource is assigned a select code as shown in table 27-33 . chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 403
table 27-32. read resource command fccob requirements fccob number fccob contents [7:0] 0 0x03 (rdrsrc) 1 flash address [23:16] 2 flash address [15:8] 3 flash address [7:0] 1 returned values 4 read data [31:24] 5 read data [23:16] 6 read data [15:8] 7 read data [7:0] user-provided values 8 resource select code (see table 27-33 ) 1. must be longword aligned (flash address [1:0] = 00). table 27-33. read resource select codes resource select code description resource size local address range 0x00 program flash 0 ifr 256 bytes 0x00_0000 - 0x00_00ff 0x01 1 version id 8 bytes 0x00_0000 - 0x00_0007 1. located in program flash 0 reserved space. after clearing ccif to launch the read resource command, four consecutive bytes are read from the selected resource at the provided relative address and stored in the fccob register. the ccif flag sets after the read resource operation completes. the read resource command exits with an access error if an invalid resource code is provided or if the address for the applicable area is out-of-range. table 27-34. read resource command error handling error condition error bit command not available in current mode/security fstat[accerr] an invalid resource code is entered fstat[accerr] flash address is out-of-range for the targeted resource. fstat[accerr] flash address is not longword aligned fstat[accerr] 27.4.10.4 program longword command the program longword command programs four previously-erased bytes in the program flash memory using an embedded algorithm. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 404 freescale semiconductor, inc.
caution a flash memory location must be in the erased state before being programmed. cumulative programming of bits (back-to- back program operations without an intervening erase) within a flash memory location is not allowed. re-programming of existing 0s to 0 is not allowed as this overstresses the device. table 27-35. program longword command fccob requirements fccob number fccob contents [7:0] 0 0x06 (pgm4) 1 flash address [23:16] 2 flash address [15:8] 3 flash address [7:0] 1 4 byte 0 program value 5 byte 1 program value 6 byte 2 program value 7 byte 3 program value 1. must be longword aligned (flash address [1:0] = 00). upon clearing ccif to launch the program longword command, the flash memory module programs the data bytes into the flash using the supplied address. the targeted flash locations must be currently unprotected (see the description of the fprot registers) to permit execution of the program longword operation. the programming operation is unidirectional. it can only move nvm bits from the erased state ('1') to the programmed state ('0'). erased bits that fail to program to the '0' state are flagged as errors in fstat[mgstat0]. the ccif flag is set after the program longword operation completes. the supplied address must be longword aligned (flash address [1:0] = 00): ? byte 3 data is written to the supplied byte address ('start'), ? byte 2 data is programmed to byte address start+0b01, ? byte 1 data is programmed to byte address start+0b10, and ? byte 0 data is programmed to byte address start+0b11. table 27-36. program longword command error handling error condition error bit command not available in current mode/security fstat[accerr] an invalid flash address is supplied fstat[accerr] flash address is not longword aligned fstat[accerr] flash address points to a protected area fstat[fpviol] table continues on the next page... chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 405
table 27-36. program longword command error handling (continued) error condition error bit any errors have been encountered during the verify operation fstat[mgstat0] 27.4.10.5 erase flash sector command the erase flash sector operation erases all addresses in a flash sector. table 27-37. erase flash sector command fccob requirements fccob number fccob contents [7:0] 0 0x09 (ersscr) 1 flash address [23:16] in the flash sector to be erased 2 flash address [15:8] in the flash sector to be erased 3 flash address [7:0] 1 in the flash sector to be erased 1. must be longword aligned (flash address [1:0] = 00). after clearing ccif to launch the erase flash sector command, the flash memory module erases the selected program flash sector and then verifies that it is erased. the erase flash sector command aborts if the selected sector is protected (see the description of the fprot registers). if the erase-verify fails the fstat[mgstat0] bit is set. the ccif flag is set after the erase flash sector operation completes. the erase flash sector command is suspendable (see the fcnfg[erssusp] bit and figure 27-26 ). table 27-38. erase flash sector command error handling error condition error bit command not available in current mode/security fstat[accerr] an invalid flash address is supplied fstat[accerr] flash address is not longword aligned fstat[accerr] the selected program flash sector is protected fstat[fpviol] any errors have been encountered during the verify operation 1 fstat[mgstat0] 1. user margin read may be run using the read 1s section command to verify all bits are erased. 27.4.10.5.1 suspending an erase flash sector operation to suspend an erase flash sector operation set the fcnfg[erssusp] bit (see flash configuration field description ) when ccif is clear and the ccob command field holds the code for the erase flash sector command. during the erase flash sector operation (see erase flash sector command ), the flash memory module samples the state of the erssusp bit at convenient points. if the flash memory module detects that the functional description kl04 sub-family reference manual, rev. 3.1, november 2012 406 freescale semiconductor, inc.
erssusp bit is set, the erase flash sector operation is suspended and the flash memory module sets ccif. while erssusp is set, all writes to flash registers are ignored except for writes to the fstat and fcnfg registers. if an erase flash sector operation effectively completes before the flash memory module detects that a suspend request has been made, the flash memory module clears the erssusp bit prior to setting ccif. when an erase flash sector operation has been successfully suspended, the flash memory module sets ccif and leaves the erssusp bit set. while ccif is set, the erssusp bit can only be cleared to prevent the withdrawal of a suspend request before the flash memory module has acknowledged it. 27.4.10.5.2 resuming a suspended erase flash sector operation if the erssusp bit is still set when ccif is cleared to launch the next command, the previous erase flash sector operation resumes. the flash memory module acknowledges the request to resume a suspended operation by clearing the erssusp bit. a new suspend request can then be made by setting erssusp. a single erase flash sector operation can be suspended and resumed multiple times. there is a minimum elapsed time limit between the request to resume the erase flash sector operation (ccif is cleared) and the request to suspend the operation again (erssusp is set). this minimum time period is required to ensure that the erase flash sector operation will eventually complete. if the minimum period is continually violated, i.e. the suspend requests come repeatedly and too quickly, no forward progress is made by the erase flash sector algorithm. the resume/suspend sequence runs indefinitely without completing the erase. 27.4.10.5.3 aborting a suspended erase flash sector operation the user may choose to abort a suspended erase flash sector operation by clearing the erssusp bit prior to clearing ccif for the next command launch. when a suspended operation is aborted, the flash memory module starts the new command using the new fccob contents. note aborting the erase leaves the bitcells in an indeterminate, partially-erased state. data in this sector is not reliable until a new erase command fully completes. the following figure shows how to suspend and resume the erase flash sector operation. chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 407
restore erase algo clear suspack = 0 ersscr command (write fccob) launch/resume command (clear ccif) ccif = 1? request suspend (set erssusp) interrupt? ccif = 1? service interrupt (read flash) erssusp=0? next command (write fccob) clear erssusp enter with ccif = 1 resume ersscr no memory controller command processing suspack=1 clear erssusp execute yes done? no erssusp=1? save erase algo set ccif no yes start new resume erase? no, abort user cmd interrupt/suspend set suspack = 1 ersscr suspended command initiation yes no yes yes ersscr completed ersscr suspended erssusp=1 erssusp: bit in fcnfg register suspack: internal suspend acknowledge no yes yes no yes no ersscr completed erssusp=0 figure 27-26. suspend and resume of erase flash sector operation functional description kl04 sub-family reference manual, rev. 3.1, november 2012 408 freescale semiconductor, inc.
27.4.10.6 read 1s all blocks command the read 1s all blocks command checks if the program flash blocks have been erased to the specified read margin level, if applicable, and releases security if the readout passes, i.e. all data reads as '1'. table 27-39. read 1s all blocks command fccob requirements fccob number fccob contents [7:0] 0 0x40 (rd1all) 1 read-1 margin choice after clearing ccif to launch the read 1s all blocks command, the flash memory module : ? sets the read margin for 1s according to table 27-40 , ? checks the contents of the program flash are in the erased state. if the flash memory module confirms that these memory resources are erased, security is released by setting the fsec[sec] field to the unsecure state. the security byte in the flash configuration field (see flash configuration field description ) remains unaffected by the read 1s all blocks command. if the read fails, i.e. all memory resources are not in the fully erased state, the fstat[mgstat0] bit is set. the ccif flag sets after the read 1s all blocks operation has completed. table 27-40. margin level choices for read 1s all blocks read margin choice margin level description 0x00 use the 'normal' read level for 1s 0x01 apply the 'user' margin to the normal read-1 level 0x02 apply the 'factory' margin to the normal read-1 level table 27-41. read 1s all blocks command error handling error condition error bit an invalid margin choice is specified fstat[accerr] read-1s fails fstat[mgstat0] chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 409
27.4.10.7 read once command the read once command provides read access to a reserved 64-byte field located in the program flash 0 ifr (see program flash ifr map and program once field ). access to this field is via 16 records, each 4 bytes long. the read once field is programmed using the program once command described in program once command . table 27-42. read once command fccob requirements fccob number fccob contents [7:0] 0 0x41 (rdonce) 1 read once record index (0x00 - 0x0f) 2 not used 3 not used returned values 4 read once byte 0 value 5 read once byte 1 value 6 read once byte 2 value 7 read once byte 3 value after clearing ccif to launch the read once command, a 4-byte read once record is read from the program flash ifr and stored in the fccob register. the ccif flag is set after the read once operation completes. valid record index values for the read once command range from 0x00 to 0x0f. during execution of the read once command, any attempt to read addresses within the program flash block containing this 64-byte field returns invalid data. the read once command can be executed any number of times. table 27-43. read once command error handling error condition error bit command not available in current mode/security fstat[accerr] an invalid record index is supplied fstat[accerr] 27.4.10.8 program once command the program once command enables programming to a reserved 64-byte field in the program flash 0 ifr (see program flash ifr map and program once field ). access to the program once field is via 16 records, each 4 bytes long. the program once field can be read using the read once command (see read once command ) or using the read resource command (see read resource command ). each program once record can be programmed only once since the program flash 0 ifr cannot be erased. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 410 freescale semiconductor, inc.
table 27-44. program once command fccob requirements fccob number fccob contents [7:0] 0 0x43 (pgmonce) 1 program once record index (0x00 - 0x0f) 2 not used 3 not used 4 program once byte 0 value 5 program once byte 1 value 6 program once byte 2 value 7 program once byte 3 value after clearing ccif to launch the program once command, the flash memory module first verifies that the selected record is erased. if erased, then the selected record is programmed using the values provided. the program once command also verifies that the programmed values read back correctly. the ccif flag is set after the program once operation has completed. the reserved program flash 0 ifr location accessed by the program once command cannot be erased and any attempt to program one of these records when the existing value is not fs (erased) is not allowed. valid record index values for the program once command range from 0x00 to 0x0f. during execution of the program once command, any attempt to read addresses within the program flash block containing this 64-byte field returns invalid data. table 27-45. program once command error handling error condition error bit command not available in current mode/security fstat[accerr] an invalid record index is supplied fstat[accerr] the requested record has already been programmed to a non-ffff value 1 fstat[accerr] any errors have been encountered during the verify operation fstat[mgstat0] 1. if a program once record is initially programmed to 0xffff_ffff, the program once command is allowed to execute again on that same record. 27.4.10.9 erase all blocks command the erase all blocks operation erases all flash memory, verifies all memory contents, and releases mcu security. chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 411
table 27-46. erase all blocks command fccob requirements fccob number fccob contents [7:0] 0 0x44 (ersall) after clearing ccif to launch the erase all blocks command, the flash memory module erases all program flash memory, then verifies that all are erased. if the flash memory module verifies that all flash memories were properly erased, security is released by setting the fsec[sec] field to the unsecure state. the erase all blocks command aborts if any flash region is protected. the security byte and all other contents of the flash configuration field (see flash configuration field description ) are erased by the erase all blocks command. if the erase-verify fails, the fstat[mgstat0] bit is set. the ccif flag is set after the erase all blocks operation completes. table 27-47. erase all blocks command error handling error condition error bit command not available in current mode/security fstat[accerr] any region of the program flash memory is protected fstat[fpviol] any errors have been encountered during the verify operation 1 fstat[mgstat0] 1. user margin read may be run using the read 1s all blocks command to verify all bits are erased. 27.4.10.9.1 triggering an erase all external to the flash memory module the functionality of the erase all blocks command is also available in an uncommanded fashion outside of the flash memory. refer to the device's chip configuration details for information on this functionality. before invoking the external erase all function, the fstat[accerr and pviol] flags must be cleared and the fccob0 register must not contain 0x44. when invoked, the erase-all function erases all program flash memory regardless of the protection settings. if the post-erase verify passes, the routine then releases security by setting the fsec[sec] field register to the unsecure state. the security byte in the flash configuration field is also programmed to the unsecure state. the status of the erase-all request is reflected in the fcnfg[ersareq] bit. the fcnfg[ersareq] bit is cleared once the operation completes and the normal fstat error reporting is available as described in erase all blocks command . functional description kl04 sub-family reference manual, rev. 3.1, november 2012 412 freescale semiconductor, inc.
27.4.10.10 verify backdoor access key command the verify backdoor access key command only executes if the mode and security conditions are satisfied (see flash commands by mode ). execution of the verify backdoor access key command is further qualified by the fsec[keyen] bits. the verify backdoor access key command releases security if user-supplied keys in the fccob match those stored in the backdoor comparison key bytes of the flash configuration field (see flash configuration field description ). the column labelled flash configuration field offset address shows the location of the matching byte in the flash configuration field. table 27-48. verify backdoor access key command fccob requirements fccob number fccob contents [7:0] flash configuration field offset address 0 0x45 (vfykey) 1-3 not used 4 key byte 0 0x0_0000 5 key byte 1 0x0_0001 6 key byte 2 0x0_0002 7 key byte 3 0x0_0003 8 key byte 4 0x0_0004 9 key byte 5 0x0_0005 a key byte 6 0x0_0006 b key byte 7 0x0_0007 after clearing ccif to launch the verify backdoor access key command, the flash memory module checks the fsec[keyen] bits to verify that this command is enabled. if not enabled, the flash memory module sets the fstat[accerr] bit and terminates. if the command is enabled, the flash memory module compares the key provided in fccob to the backdoor comparison key in the flash configuration field. if the backdoor keys match, the fsec[sec] field is changed to the unsecure state and security is released. if the backdoor keys do not match, security is not released and all future attempts to execute the verify backdoor access key command are immediately aborted and the fstat[accerr] bit is (again) set to 1 until a reset of the flash memory module module occurs. if the entire 8-byte key is all zeros or all ones, the verify backdoor access key command fails with an access error. the ccif flag is set after the verify backdoor access key operation completes. table 27-49. verify backdoor access key command error handling error condition error bit the supplied key is all-0s or all-fs fstat[accerr] an incorrect backdoor key is supplied fstat[accerr] table continues on the next page... chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 413
table 27-49. verify backdoor access key command error handling (continued) error condition error bit backdoor key access has not been enabled (see the description of the fsec register) fstat[accerr] this command is launched and the backdoor key has mismatched since the last power down reset fstat[accerr] 27.4.11 security the flash memory module provides security information to the mcu based on contents of the fsec security register. the mcu then limits access to flash memory resources as defined in the device's chip configuration details. during reset, the flash memory module initializes the fsec register using data read from the security byte of the flash configuration field (see flash configuration field description ). the following fields are available in the fsec register. the settings are described in the flash security register (ftfa_fsec) details. table 27-50. fsec register fields fsec field description keyen backdoor key access meen mass erase capability fslacc freescale factory access sec mcu security 27.4.11.1 flash memory access by mode and security the following table summarizes how access to the flash memory module is affected by security and operating mode. table 27-51. flash memory access summary operating mode chip security state unsecure secure nvm normal full command set nvm special full command set only the erase all blocks and read 1s all blocks commands. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 414 freescale semiconductor, inc.
27.4.11.2 changing the security state the security state out of reset can be permanently changed by programming the security byte of the flash configuration field. this assumes that you are starting from a mode where the necessary program flash erase and program commands are available and that the region of the program flash containing the flash configuration field is unprotected. if the flash security byte is successfully programmed, its new value takes affect after the next chip reset. 27.4.11.2.1 unsecuring the chip using backdoor key access the chip can be unsecured by using the backdoor key access feature, which requires knowledge of the contents of the 8-byte backdoor key value stored in the flash configuration field (see flash configuration field description ). if the fsec[keyen] bits are in the enabled state, the verify backdoor access key command (see verify backdoor access key command ) can be run; it allows the user to present prospective keys for comparison to the stored keys. if the keys match, the fsec[sec] bits are changed to unsecure the chip. the entire 8-byte key cannot be all 0s or all 1s; that is, 0000_0000_0000_0000h and ffff_ffff_ffff_ffffh are not accepted by the verify backdoor access key command as valid comparison values. while the verify backdoor access key command is active, program flash memory is not available for read access and returns invalid data. the user code stored in the program flash memory must have a method of receiving the backdoor keys from an external stimulus. this external stimulus would typically be through one of the on-chip serial ports. if the keyen bits are in the enabled state, the chip can be unsecured by the following backdoor key access sequence: 1. follow the command sequence for the verify backdoor access key command as explained in verify backdoor access key command 2. if the verify backdoor access key command is successful, the chip is unsecured and the fsec[sec] bits are forced to the unsecure state an illegal key provided to the verify backdoor access key command prohibits further use of the verify backdoor access key command. a reset of the chip is the only method to re-enable the verify backdoor access key command when a comparison fails. after the backdoor keys have been correctly matched, the chip is unsecured by changing the fsec[sec] bits. a successful execution of the verify backdoor access key command changes the security in the fsec register only. it does not alter the security byte or the keys stored in the flash configuration field ( flash configuration field description ). after the next reset of the chip, the security state of the flash memory chapter 27 flash memory module (ftfa) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 415
module reverts back to the flash security byte in the flash configuration field. the verify backdoor access key command sequence has no effect on the program and erase protections defined in the program flash protection registers. if the backdoor keys successfully match, the unsecured chip has full control of the contents of the flash configuration field. the chip may erase the sector containing the flash configuration field and reprogram the flash security byte to the unsecure state and change the backdoor keys to any desired value. 27.4.12 reset sequence on each system reset the flash memory module executes a sequence which establishes initial values for the flash block configuration parameters, fprot, fopt, and fsec registers. fstat[ccif] is cleared throughout the reset sequence. the flash memory module holds off cpu access during the reset sequence. flash reads are possible when the hold is removed. completion of the reset sequence is marked by setting ccif which enables flash user commands. if a reset occurs while any flash command is in progress, that command is immediately aborted. the state of the word being programmed or the sector/block being erased is not guaranteed. commands and operations do not automatically resume after exiting reset. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 416 freescale semiconductor, inc.
chapter 28 analog-to-digital converter (adc) 28.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the 12-bit analog-to-digital converter (adc) is a successive approximation adc designed for operation within an integrated microcontroller system-on-chip. note for the chip specific modes of operation, see the power management information of the device. 28.1.1 features features of the adc module include: ? linear successive approximation algorithm with up to 12-bit resolution ? up to 24 single-ended external analog inputs ? output modes: ? single-ended 12-bit, 10-bit, and 8-bit modes ? output in right-justified unsigned format for single-ended ? single or continuous conversion, that is, automatic return to idle after single conversion ? configurable sample time and conversion speed/power ? conversion complete/hardware average complete flag and interrupt kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 417
? input clock selectable from up to four sources ? operation in low-power modes for lower noise ? asynchronous clock source for lower noise operation with option to output the clock ? selectable hardware conversion trigger with hardware channel select ? automatic compare with interrupt for less-than, greater-than or equal-to, within range, or out-of-range, programmable value ? temperature sensor ? hardware average function ? selectable voltage reference: external or alternate ? self-calibration mode 28.1.2 block diagram the following figure is the adc module block diagram. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 418 freescale semiconductor, inc.
sc1a adhwtsa adhwtsn c o m p a r e t r u e a d c h c o m p l e t e a d t r g a d c o control registers sc1n a d i v a d i c l k async clock gen a d a c k e n 2 altclk adack a d c k m o d e t r a n s f e r c v 2 cv1:cv2 interrupt 1 a d v i n a c f e 1 sc2 rn ra cfg1,2 c l m x clmx compare true conversion trigger control mcu stop adhwt ad0 ad23 temp v refh v alth v refl v altl aien c o c o t r i g g e r m o d e clpx pg, mg pg, mg clpx c a l i b r ation ofs calf cal sc3 c v1 acfgt, acren d a v g e , a v gs adcofs v refsh v refsl (sc2, cfg1, cfg2) adlsmp/adlsts adlpc/adhsc control sequencer clock divide bus clock sar converter offset subtractor averager formatting compare logic initialize sample convert transfer abort figure 28-1. adc block diagram 28.2 adc signal descriptions the adc module supports up to 24 single-ended inputs. the adc also requires four supply/reference/ground connections. note refer to adc configuration section in chip configuration chapter for the number of channels supported on this device. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 419
table 28-1. adc signal descriptions signal description i/o ad n single-ended analog channel inputs i v refsh voltage reference select high i v refsl voltage reference select low i v dda analog power supply i v ssa analog ground i 28.2.1 analog power (v dda ) the adc analog portion uses v dda as its power connection. in some packages, v dda is connected internally to v dd . if externally available, connect the v dda pin to the same voltage potential as v dd . external filtering may be necessary to ensure clean v dda for good results. 28.2.2 analog ground (v ssa ) the adc analog portion uses v ssa as its ground connection. in some packages, v ssa is connected internally to v ss . if externally available, connect the v ssa pin to the same voltage potential as v ss . 28.2.3 voltage reference select v refsh and v refsl are the high and low reference voltages for the adc module. the adc can be configured to accept one of two voltage reference pairs for v refsh and v refsl . each pair contains a positive reference that must be between the minimum ref voltage high and v dda , and a ground reference that must be at the same potential as v ssa . the two pairs are external (v refh and v refl ) and alternate (v alth and v altl ). these voltage references are selected using sc2[refsel]. the alternate v alth and v altl voltage reference pair may select additional external pins or internal sources depending on mcu configuration. see the chip configuration information on the voltage references specific to this mcu. adc signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 420 freescale semiconductor, inc.
in some packages, v refh is connected in the package to v dda and v refl to v ssa . if externally available, the positive reference(s) may be connected to the same potential as v dda or may be driven by an external source to a level between the minimum ref voltage high and the v dda potential. v refh must never exceed v dda . connect the ground references to the same voltage potential as v ssa . 28.2.4 analog channel inputs (adx) the adc module supports up to 24 single-ended analog inputs. a single-ended input is selected for conversion through the sc1[adch] channel select bits. 28.3 register definition this section describes the adc registers. adc memory map absolute address (hex) register name width (in bits) access reset value section/ page 4003_b000 adc status and control registers 1 (adc0_sc1a) 32 r/w 0000_001fh 28.3.1/422 4003_b004 adc status and control registers 1 (adc0_sc1b) 32 r/w 0000_001fh 28.3.1/422 4003_b008 adc configuration register 1 (adc0_cfg1) 32 r/w 0000_0000h 28.3.2/425 4003_b00c adc configuration register 2 (adc0_cfg2) 32 r/w 0000_0000h 28.3.3/427 4003_b010 adc data result register (adc0_ra) 32 r 0000_0000h 28.3.4/428 4003_b014 adc data result register (adc0_rb) 32 r 0000_0000h 28.3.4/428 4003_b018 compare value registers (adc0_cv1) 32 r/w 0000_0000h 28.3.5/429 4003_b01c compare value registers (adc0_cv2) 32 r/w 0000_0000h 28.3.5/429 4003_b020 status and control register 2 (adc0_sc2) 32 r/w 0000_0000h 28.3.6/430 4003_b024 status and control register 3 (adc0_sc3) 32 r/w 0000_0000h 28.3.7/432 4003_b028 adc offset correction register (adc0_ofs) 32 r/w 0000_0004h 28.3.8/433 4003_b02c adc plus-side gain register (adc0_pg) 32 r/w 0000_8200h 28.3.9/434 4003_b034 adc plus-side general calibration value register (adc0_clpd) 32 r/w 0000_000ah 28.3.10/434 4003_b038 adc plus-side general calibration value register (adc0_clps) 32 r/w 0000_0020h 28.3.11/435 4003_b03c adc plus-side general calibration value register (adc0_clp4) 32 r/w 0000_0200h 28.3.12/435 4003_b040 adc plus-side general calibration value register (adc0_clp3) 32 r/w 0000_0100h 28.3.13/436 4003_b044 adc plus-side general calibration value register (adc0_clp2) 32 r/w 0000_0080h 28.3.14/436 table continues on the next page... chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 421
adc memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page 4003_b048 adc plus-side general calibration value register (adc0_clp1) 32 r/w 0000_0040h 28.3.15/437 4003_b04c adc plus-side general calibration value register (adc0_clp0) 32 r/w 0000_0020h 28.3.16/437 28.3.1 adc status and control registers 1 (adc x _sc1 n ) sc1a is used for both software and hardware trigger modes of operation. to allow sequential conversions of the adc to be triggered by internal peripherals, the adc can have more then one status and control register: one for each conversion. the sc1bCsc1n registers indicate potentially multiple sc1 registers for use only in hardware trigger mode. see the chip configuration information about the number of sc1n registers specific to this device. the sc1n registers have identical fields, and are used in a "ping- pong" approach to control adc operation. at any one point in time, only one of the sc1n registers is actively controlling adc conversions. updating sc1a while sc1n is actively controlling a conversion is allowed, and vice-versa for any of the sc1n registers specific to this mcu. writing sc1a while sc1a is actively controlling a conversion aborts the current conversion. in software trigger mode, when sc2[adtrg]=0, writes to sc1a subsequently initiate a new conversion, if sc1[adch] contains a value other than all 1s. writing any of the sc1n registers while that specific sc1n register is actively controlling a conversion aborts the current conversion. none of the sc1b-sc1n registers are used for software trigger operation and therefore writes to the sc1bCsc1n registers do not initiate a new conversion. register definition kl04 sub-family reference manual, rev. 3.1, november 2012 422 freescale semiconductor, inc.
address: 4003_b000h base + 0h offset + (4d i), where i=0d to 1d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 coco aien reserved adch w reset 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 423
adc x _sc1 n field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 coco conversion complete flag this is a read-only field that is set each time a conversion is completed when the compare function is disabled, or sc2[acfe]=0 and the hardware average function is disabled, or sc3[avge]=0. when the compare function is enabled, or sc2[acfe]=1, coco is set upon completion of a conversion only if the compare result is true. when the hardware average function is enabled, or sc3[avge]=1, coco is set upon completion of the selected number of conversions (determined by avgs). coco in sc1a is also set at the completion of a calibration sequence. coco is cleared when the respective sc1n register is written or when the respective rn register is read. 0 conversion is not completed. 1 conversion is completed. 6 aien interrupt enable enables conversion complete interrupts. when coco becomes set while the respective aien is high, an interrupt is asserted. 0 conversion complete interrupt is disabled. 1 conversion complete interrupt is enabled. 5 reserved this field is reserved. this reserved bit should not be changed. 4C0 adch input channel select selects one of the input channels. note: some of the input channel options in the bitfield-setting descriptions might not be available for your device. for the actual adc channel assignments for your device, see the chip configuration details. the successive approximation converter subsystem is turned off when the channel select bits are all set, that is, adch = 11111. this feature allows explicit disabling of the adc and isolation of the input channel from all sources. terminating continuous conversions this way prevents an additional single conversion from being performed. it is not necessary to set adch to all 1s to place the adc in a low-power state when continuous conversions are not enabled because the module automatically enters a low-power state when a conversion completes. 00000 ad0 is selected as input. 00001 ad1 is selected as input. 00010 ad2 is selected as input. 00011 ad3 is selected as input. 00100 ad4 is selected as input. 00101 ad5 is selected as input. 00110 ad6 is selected as input. 00111 ad7 is selected as input. 01000 ad8 is selected as input. 01001 ad9 is selected as input. 01010 ad10 is selected as input. 01011 ad11 is selected as input. 01100 ad12 is selected as input. 01101 ad13 is selected as input. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 424 freescale semiconductor, inc.
adc x _sc1 n field descriptions (continued) field description 01110 ad14 is selected as input. 01111 ad15 is selected as input. 10000 ad16 is selected as input. 10001 ad17 is selected as input. 10010 ad18 is selected as input. 10011 ad19 is selected as input. 10100 ad20 is selected as input. 10101 ad21 is selected as input. 10110 ad22 is selected as input. 10111 ad23 is selected as input. 11000 reserved. 11001 reserved. 11010 temp sensor (single-ended) is selected as input. 11011 bandgap (single-ended) is selected as input. 11100 reserved. 11101 v refsh is selected as input. voltage reference selected is determined by sc2[refsel]. 11110 v refsl is selected as input. voltage reference selected is determined by sc2[refsel]. 11111 module is disabled. 28.3.2 adc configuration register 1 (adc x _cfg1) the configuration register 1 (cfg1) selects the mode of operation, clock source, clock divide, and configuration for low power or long sample time. address: 4003_b000h base + 8h offset = 4003_b008h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 adlpc adiv adlsmp mode adiclk w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 adc x _cfg1 field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 425
adc x _cfg1 field descriptions (continued) field description 7 adlpc low-power configuration controls the power configuration of the successive approximation converter. this optimizes power consumption when higher sample rates are not required. 0 normal power configuration. 1 low-power configuration. the power is reduced at the expense of maximum clock speed. 6C5 adiv clock divide select adiv selects the divide ratio used by the adc to generate the internal clock adck. 00 the divide ratio is 1 and the clock rate is input clock. 01 the divide ratio is 2 and the clock rate is (input clock)/2. 10 the divide ratio is 4 and the clock rate is (input clock)/4. 11 the divide ratio is 8 and the clock rate is (input clock)/8. 4 adlsmp sample time configuration adlsmp selects between different sample times based on the conversion mode selected. this bit adjusts the sample period to allow higher impedance inputs to be accurately sampled or to maximize conversion speed for lower impedance inputs. longer sample times can also be used to lower overall power consumption if continuous conversions are enabled and high conversion rates are not required. when adlsmp=1, the long sample time select bits, (adlsts[1:0]), can select the extent of the long sample time. 0 short sample time. 1 long sample time. 3C2 mode conversion mode selection selects the adc resolution mode. 00 it is single-ended 8-bit conversion. 01 it is single-ended 12-bit conversion . 10 it is single-ended 10-bit conversion . 11 reserved. do not set the bitfield to this value. 1C0 adiclk input clock select selects the input clock source to generate the internal clock, adck. note that when the adack clock source is selected, it is not required to be active prior to conversion start. when it is selected and it is not active prior to a conversion start, when cfg2[adacken]=0, the asynchronous clock is activated at the start of a conversion and deactivated when conversions are terminated. in this case, there is an associated clock startup delay each time the clock source is re-activated. 00 bus clock 01 (bus clock)/2 10 alternate clock (altclk) 11 asynchronous clock (adack) register definition kl04 sub-family reference manual, rev. 3.1, november 2012 426 freescale semiconductor, inc.
28.3.3 adc configuration register 2 (adc x _cfg2) configuration register 2 (cfg2) selects the special high-speed configuration for very high speed conversions and selects the long sample time duration during long sample mode. address: 4003_b000h base + ch offset = 4003_b00ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 0 muxsel adacken adhsc adlsts w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 adc x _cfg2 field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7C5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4 muxsel adc mux select changes the adc mux setting to select between alternate sets of adc channels. 0 adxxa channels are selected. 1 adxxb channels are selected. 3 adacken asynchronous clock output enable enables the asynchronous clock source and the clock source output regardless of the conversion and status of cfg1[adiclk]. based on mcu configuration, the asynchronous clock may be used by other modules. see chip configuration information. setting this field allows the clock to be used even while the adc is idle or operating from a different clock source. also, latency of initiating a single or first-continuous conversion with the asynchronous clock selected is reduced because the adack clock is already operational. 0 asynchronous clock output disabled; asynchronous clock is enabled only if selected by adiclk and a conversion is active. 1 asynchronous clock and clock output is enabled regardless of the state of the adc. 2 adhsc high-speed configuration table continues on the next page... chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 427
adc x _cfg2 field descriptions (continued) field description configures the adc for very high-speed operation. the conversion sequence is altered with 2 adck cycles added to the conversion time to allow higher speed conversion clocks. 0 normal conversion sequence selected. 1 high-speed conversion sequence selected with 2 additional adck cycles to total conversion time. 1C0 adlsts long sample time select selects between the extended sample times when long sample time is selected, that is, when cfg1[adlsmp]=1. this allows higher impedance inputs to be accurately sampled or to maximize conversion speed for lower impedance inputs. longer sample times can also be used to lower overall power consumption when continuous conversions are enabled if high conversion rates are not required. 00 default longest sample time; 20 extra adck cycles; 24 adck cycles total. 01 12 extra adck cycles; 16 adck cycles total sample time. 10 6 extra adck cycles; 10 adck cycles total sample time. 11 2 extra adck cycles; 6 adck cycles total sample time. 28.3.4 adc data result register (adc x _r n ) the data result registers (rn) contain the result of an adc conversion of the channel selected by the corresponding status and channel control register (sc1a:sc1n). for every status and channel control register, there is a corresponding data result register. unused bits in r n are cleared in unsigned right-justified modes and carry the sign bit (msb) in sign-extended 2's complement modes. the following table describes the behavior of the data result registers in the different modes of operation. table 28-35. data result register description conversion mode d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0 format 12-bit single- ended 0 0 0 0 d d d d d d d d d d d d unsigned right- justified 10-bit single- ended 0 0 0 0 0 0 d d d d d d d d d d unsigned right- justified 8-bit single- ended 0 0 0 0 0 0 0 0 d d d d d d d d unsigned right- justified note s: sign bit or sign bit extension; d: data, which is 2's complement data if indicated register definition kl04 sub-family reference manual, rev. 3.1, november 2012 428 freescale semiconductor, inc.
address: 4003_b000h base + 10h offset + (4d i), where i=0d to 1d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 d w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 adc x _r n field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 d data result 28.3.5 compare value registers (adc x _cv n ) the compare value registers (cv1 and cv2) contain a compare value used to compare the conversion result when the compare function is enabled, that is, sc2[acfe]=1. this register is formatted in the same way as the rn registers in different modes of operation for both bit position definition and value format using unsigned or sign-extended 2's complement. therefore, the compare function uses only the cvn fields that are related to the adc mode of operation. the compare value 2 register (cv2) is used only when the compare range function is enabled, that is, sc2[acren]=1. address: 4003_b000h base + 18h offset + (4d i), where i=0d to 1d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 cv w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 adc x _cv n field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 cv compare value. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 429
28.3.6 status and control register 2 (adc x _sc2) the status and control register 2 (sc2) contains the conversion active, hardware/software trigger select, compare function, and voltage reference select of the adc module. address: 4003_b000h base + 20h offset = 4003_b020h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 adact adtrg acfe acfgt acren dmaen refsel w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 adc x _sc2 field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 adact conversion active indicates that a conversion or hardware averaging is in progress. adact is set when a conversion is initiated and cleared when a conversion is completed or aborted. 0 conversion not in progress. 1 conversion in progress. 6 adtrg conversion trigger select selects the type of trigger used for initiating a conversion. two types of trigger are selectable: table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 430 freescale semiconductor, inc.
adc x _sc2 field descriptions (continued) field description ? software trigger: when software trigger is selected, a conversion is initiated following a write to sc1a. ? hardware trigger: when hardware trigger is selected, a conversion is initiated following the assertion of the adhwt input after a pulse of the adhwtsn input. 0 software trigger selected. 1 hardware trigger selected. 5 acfe compare function enable enables the compare function. 0 compare function disabled. 1 compare function enabled. 4 acfgt compare function greater than enable configures the compare function to check the conversion result relative to the cv1 and cv2 based upon the value of acren. acfe must be set for acfgt to have any effect. 0 configures less than threshold, outside range not inclusive and inside range not inclusive; functionality based on the values placed in cv1 and cv2. 1 configures greater than or equal to threshold, outside and inside ranges inclusive; functionality based on the values placed in cv1 and cv2. 3 acren compare function range enable configures the compare function to check if the conversion result of the input being monitored is either between or outside the range formed by cv1 and cv2 determined by the value of acfgt. acfe must be set for acfgt to have any effect. 0 range function disabled. only cv1 is compared. 1 range function enabled. both cv1 and cv2 are compared. 2 dmaen dma enable 0 dma is disabled. 1 dma is enabled and will assert the adc dma request during an adc conversion complete event noted when any of the sc1n[coco] flags is asserted. 1C0 refsel voltage reference selection selects the voltage reference source used for conversions. 00 default voltage reference pin pair, that is, external pins v refh and v refl 01 alternate reference pair, that is, v alth and v altl . this pair may be additional external pins or internal sources depending on the mcu configuration. see the chip configuration information for details specific to this mcu 10 reserved 11 reserved chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 431
28.3.7 status and control register 3 (adc x _sc3) the status and control register 3 (sc3) controls the calibration, continuous convert, and hardware averaging functions of the adc module. address: 4003_b000h base + 24h offset = 4003_b024h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 cal calf 0 adco avge avgs w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 adc x _sc3 field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 cal calibration begins the calibration sequence when set. this field stays set while the calibration is in progress and is cleared when the calibration sequence is completed. calf must be checked to determine the result of the calibration sequence. once started, the calibration routine cannot be interrupted by writes to the adc registers or the results will be invalid and calf will set. setting cal will abort any current conversion. 6 calf calibration failed flag displays the result of the calibration sequence. the calibration sequence will fail if sc2[adtrg] = 1, any adc register is written, or any stop mode is entered before the calibration sequence completes. writing 1 to calf clears it. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 432 freescale semiconductor, inc.
adc x _sc3 field descriptions (continued) field description 0 calibration completed normally. 1 calibration failed. adc accuracy specifications are not guaranteed. 5C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 adco continuous conversion enable enables continuous conversions. 0 one conversion or one set of conversions if the hardware average function is enabled, that is, avge=1, after initiating a conversion. 1 continuous conversions or sets of conversions if the hardware average function is enabled, that is, avge=1, after initiating a conversion. 2 avge hardware average enable enables the hardware average function of the adc. 0 hardware average function disabled. 1 hardware average function enabled. 1C0 avgs hardware average select determines how many adc conversions will be averaged to create the adc average result. 00 4 samples averaged. 01 8 samples averaged. 10 16 samples averaged. 11 32 samples averaged. 28.3.8 adc offset correction register (adc x _ofs) the adc offset correction register (ofs) contains the user-selected or calibration- generated offset error correction value. this register is a 2s complement, left-justified, 16-bit value . the value in ofs is subtracted from the conversion and the result is transferred into the result registers, rn. if the result is greater than the maximum or less than the minimum result value, it is forced to the appropriate limit for the current mode of operation. address: 4003_b000h base + 28h offset = 4003_b028h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 ofs w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 433
adc x _ofs field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 ofs offset error correction value 28.3.9 adc plus-side gain register (adc x _pg) the plus-side gain register (pg) contains the gain error correction for the overall conversion in single-ended mode. pg, a 16-bit real number in binary format, is the gain adjustment factor, with the radix point fixed between adpg15 and adpg14. this register must be written by the user with the value described in the calibration procedure. otherwise, the gain error specifications may not be met. address: 4003_b000h base + 2ch offset = 4003_b02ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 pg w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 adc x _pg field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 pg plus-side gain 28.3.10 adc plus-side general calibration value register (adc x _clpd) the plus-side general calibration value registers (clpx) contain calibration information that is generated by the calibration function. these registers contain seven calibration values of varying widths: clp0[5:0], clp1[6:0], clp2[7:0], clp3[8:0], clp4[9:0], clps[5:0], and clpd[5:0]. clpx are automatically set when the self- calibration sequence is done, that is, cal is cleared. if these registers are written by the user after calibration, the linearity error specifications may not be met. register definition kl04 sub-family reference manual, rev. 3.1, november 2012 434 freescale semiconductor, inc.
address: 4003_b000h base + 34h offset = 4003_b034h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clpd w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 adc x _clpd field descriptions field description 31C6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5C0 clpd calibration value 28.3.11 adc plus-side general calibration value register (adc x _clps) for more information, see clpd register description. address: 4003_b000h base + 38h offset = 4003_b038h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clps w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 adc x _clps field descriptions field description 31C6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5C0 clps calibration value 28.3.12 adc plus-side general calibration value register (adc x _clp4) for more information, see clpd register description. address: 4003_b000h base + 3ch offset = 4003_b03ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clp4 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 435
adc x _clp4 field descriptions field description 31C10 reserved this field is reserved. this read-only field is reserved and always has the value 0. 9C0 clp4 calibration value 28.3.13 adc plus-side general calibration value register (adc x _clp3) for more information, see clpd register description. address: 4003_b000h base + 40h offset = 4003_b040h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clp3 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 adc x _clp3 field descriptions field description 31C9 reserved this field is reserved. this read-only field is reserved and always has the value 0. 8C0 clp3 calibration value 28.3.14 adc plus-side general calibration value register (adc x _clp2) for more information, see clpd register description. address: 4003_b000h base + 44h offset = 4003_b044h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clp2 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 adc x _clp2 field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7C0 clp2 calibration value register definition kl04 sub-family reference manual, rev. 3.1, november 2012 436 freescale semiconductor, inc.
28.3.15 adc plus-side general calibration value register (adc x _clp1) for more information, see clpd register description. address: 4003_b000h base + 48h offset = 4003_b048h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clp1 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 adc x _clp1 field descriptions field description 31C7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6C0 clp1 calibration value 28.3.16 adc plus-side general calibration value register (adc x _clp0) for more information, see clpd register description. address: 4003_b000h base + 4ch offset = 4003_b04ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 clp0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 adc x _clp0 field descriptions field description 31C6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5C0 clp0 calibration value chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 437
28.4 functional description the adc module is disabled during reset, in low-power stop mode, or when sc1n[adch] are all high; see the power management information for details. the module is idle when a conversion has completed and another conversion has not been initiated. when it is idle and the asynchronous clock output enable is disabled, or cfg2[adacken]= 0, the module is in its lowest power state. the adc can perform an analog-to-digital conversion on any of the software selectable channels. all modes perform conversion by a successive approximation algorithm. to meet accuracy specifications, the adc module must be calibrated using the on-chip calibration function. see calibration function for details on how to perform calibration. when the conversion is completed, the result is placed in the rn data registers. the respective sc1n[coco] is then set and an interrupt is generated if the respective conversion complete interrupt has been enabled, or, when sc1n[aien]=1. the adc module has the capability of automatically comparing the result of a conversion with the contents of the cv1 and cv2 registers. the compare function is enabled by setting sc2[acfe] and operates in any of the conversion modes and configurations. the adc module has the capability of automatically averaging the result of multiple conversions. the hardware average function is enabled by setting sc3[avge] and operates in any of the conversion modes and configurations. note for the chip specific modes of operation, see the power management information of this mcu. 28.4.1 clock select and divide control one of four clock sources can be selected as the clock source for the adc module. this clock source is then divided by a configurable value to generate the input clock adck, to the module. the clock is selected from one of the following sources by means of cfg1[adiclk]. ? bus clock. this is the default selection following reset. ? bus clock divided by two. for higher bus clock rates, this allows a maximum divide- by-16 of the bus clock using cfg1[adiv]. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 438 freescale semiconductor, inc.
? altclk: as defined for this mcu. see the chip configuration information. ? asynchronous clock (adack): this clock is generated from a clock source within the adc module. when the adack clock source is selected, it is not required to be active prior to conversion start. when it is selected and it is not active prior to a conversion start cfg2[adacken]=0, adack is activated at the start of a conversion and deactivated when conversions are terminated. in this case, there is an associated clock startup delay each time the clock source is re-activated. to avoid the conversion time variability and latency associated with the adack clock startup, set cfg2[adacken]=1 and wait the worst-case startup time of 5 s prior to initiating any conversions using the adack clock source. conversions are possible using adack as the input clock source while the mcu is in normal stop mode. see power control for more information. whichever clock is selected, its frequency must fall within the specified frequency range for adck. if the available clocks are too slow, the adc may not perform according to specifications. if the available clocks are too fast, the clock must be divided to the appropriate frequency. this divider is specified by cfg1[adiv] and can be divide-by 1, 2, 4, or 8. 28.4.2 voltage reference selection the adc can be configured to accept one of the two voltage reference pairs as the reference voltage (v refsh and v refsl ) used for conversions. each pair contains a positive reference that must be between the minimum ref voltage high and v dda , and a ground reference that must be at the same potential as v ssa . the two pairs are external (v refh and v refl ) and alternate (v alth and v altl ). these voltage references are selected using sc2[refsel]. the alternate (v alth and v altl ) voltage reference pair may select additional external pins or internal sources depending on mcu configuration. see the chip configuration information on the voltage references specific to this mcu. 28.4.3 hardware trigger and channel selects the adc module has a selectable asynchronous hardware conversion trigger, adhwt, that is enabled when sc2[adtrg] is set and a hardware trigger select event, adhwtsn, has occurred. this source is not available on all mcus. see the chip configuration chapter for information on the adhwt source and the adhwtsn configurations specific to this mcu. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 439
when an adhwt source is available and hardware trigger is enabled, that is sc2[adtrg]=1, a conversion is initiated on the rising-edge of adhwt after a hardware trigger select event, that is, adhwtsn, has occurred. if a conversion is in progress when a rising-edge of a trigger occurs, the rising-edge is ignored. in continuous convert configuration, only the initial rising-edge to launch continuous conversions is observed, and until conversion is aborted, the adc continues to do conversions on the same scn register that initiated the conversion. the hardware trigger function operates in conjunction with any of the conversion modes and configurations. the hardware trigger select event, that is, adhwtsn, must be set prior to the receipt of the adhwt signal. if these conditions are not met, the converter may ignore the trigger or use the incorrect configuration. if a hardware trigger select event is asserted during a conversion, it must stay asserted until the end of current conversion and remain set until the receipt of the adhwt signal to trigger a new conversion. the channel and status fields selected for the conversion depend on the active trigger select signal: ? adhwtsa active selects sc1a ? adhwtsn active selects sc1n note asserting more than one hardware trigger select signal (adhwtsn) at the same time results in unknown results. to avoid this, select only one hardware trigger select signal (adhwtsn) prior to the next intended conversion. when the conversion is completed, the result is placed in the rn registers associated with the adhwtsn received. for example: ? adhwtsa active selects ra register ? adhwtsn active selects rn register the conversion complete flag associated with the adhwtsn received, that is, sc1n[coco], is then set and an interrupt is generated if the respective conversion complete interrupt has been enabled, that is, sc1[aien]=1. 28.4.4 conversion control conversions can be performed as determined by cfg1[mode] as shown in the description of cfg1[mode]. conversions can be initiated by a software or hardware trigger. in addition, the adc module can be configured for: ? low-power operation ? long sample time functional description kl04 sub-family reference manual, rev. 3.1, november 2012 440 freescale semiconductor, inc.
? continuous conversion ? hardware average ? automatic compare of the conversion result to a software determined compare value 28.4.4.1 initiating conversions a conversion is initiated: ? following a write to sc1a, with sc1n[adch] not all 1's, if software triggered operation is selected, that is, when sc2[adtrg]=0. ? following a hardware trigger, or adhwt event, if hardware triggered operation is selected, that is, sc2[adtrg]=1, and a hardware trigger select event, adhwtsn, has occurred. the channel and status fields selected depend on the active trigger select signal: ? adhwtsa active selects sc1a ? adhwtsn active selects sc1n ? if neither is active, the off condition is selected note selecting more than one adhwtsn prior to a conversion completion will result in unknown results. to avoid this, select only one adhwtsn prior to a conversion completion. ? following the transfer of the result to the data registers when continuous conversion is enabled, that is, when adco=1. if continuous conversions are enabled, a new conversion is automatically initiated after the completion of the current conversion, by:. in software triggered operation, that is, when adtrg=0, continuous conversions begin after sc1a is written and continue until aborted. in hardware triggered operation, that is, when adtrg=1 and one adhwtsn event has occurred, continuous conversions begin after a hardware trigger event and continue until aborted. if hardware averaging is enabled, a new conversion is automatically initiated after the completion of the current conversion until the correct number of conversions are completed. in software triggered operation, conversions begin after sc1a is written. in hardware triggered operation, conversions begin after a hardware trigger. if continuous conversions are also enabled, a new set of conversions to be averaged are initiated following the last of the selected number of conversions. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 441
28.4.4.2 completing conversions a conversion is completed when the result of the conversion is transferred into the data result registers, rn. if the compare functions are disabled, this is indicated by setting of sc1n[coco]. if hardware averaging is enabled, the respective sc1n[coco] sets only if the last of the selected number of conversions is completed. if the compare function is enabled, the respective sc1n[coco] sets and conversion result data is transferred only if the compare condition is true. if both hardware averaging and compare functions are enabled, then the respective sc1n[coco] sets only if the last of the selected number of conversions is completed and the compare condition is true. an interrupt is generated if the respective sc1n[aien] is high at the time that the respective sc1n[coco] is set. 28.4.4.3 aborting conversions any conversion in progress is aborted when: ? writing to sc1a while it is actively controlling a conversion, aborts the current conversion. in software trigger mode, when sc2[adtrg]=0, a write to sc1a initiates a new conversion if sc1a[adch] is equal to a value other than all 1s. writing to any of the sc1bCsc1n registers while that specific sc1bCsc1n register is actively controlling a conversion aborts the current conversion. the sc1(b-n) registers are not used for software trigger operation and therefore writes to the sc1(b-n) registers do not initiate a new conversion. ? a write to any adc register besides the sc1a-sc1n registers occurs. this indicates that a change in mode of operation has occurred and the current conversion is therefore invalid. ? the mcu is reset or enters low-power stop modes. ? the mcu enters normal stop mode with adack not enabled. when a conversion is aborted, the contents of the data registers, rn, are not altered. the data registers continue to be the values transferred after the completion of the last successful conversion. if the conversion was aborted by a reset or low-power stop modes, ra and rn return to their reset states. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 442 freescale semiconductor, inc.
28.4.4.4 power control the adc module remains in its idle state until a conversion is initiated. if adack is selected as the conversion clock source, but the asynchronous clock output is disabled, that is cfg2[adacken]=0, the adack clock generator also remains in its idle state (disabled) until a conversion is initiated. if the asynchronous clock output is enabled, that is, cfg2[adacken]=1, it remains active regardless of the state of the adc or the mcu power mode. power consumption when the adc is active can be reduced by setting cfg1[adlpc]. this results in a lower maximum value for f adck . 28.4.4.5 sample time and total conversion time for short sample, that is, when cfg1[adlsmp]=0, there is a 2-cycle adder for first conversion over the base sample time of four adck cycles. for high speed conversions, that is, when cfg2[adhsc]=1, there is an additional 2-cycle adder on any conversion. the table below summarizes sample times for the possible adc configurations. adc configuration sample time (adck cycles) cfg1[adlsmp] cfg2[adlsts] cfg2[adhsc] first or single subsequent 0 x 0 6 4 1 00 0 24 1 01 0 16 1 10 0 10 1 11 0 6 0 x 1 8 6 1 00 1 26 1 01 1 18 1 10 1 12 1 11 1 8 the total conversion time depends upon: ? the sample time as determined by cfg1[adlsmp] and cfg2[adlsts] ? the mcu bus frequency ? the conversion mode, as determined by cfg1[mode] ? the high speed configuration, that is, cfg2[adhsc] ? the frequency of the conversion clock, that is, f adck . chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 443
cfg2[adhsc] is used to configure a higher clock input frequency. this will allow faster overall conversion times. to meet internal adc timing requirements, cfg2[adhsc] adds additional adck cycles. conversions with cfg2[adhsc]=1 take two more adck cycles. cfg2[adhsc] must be used when the adclk exceeds the limit for cfg2[adhsc]=0. after the module becomes active, sampling of the input begins. 1. cfg1[adlsmp] and cfg2[adlsts] select between sample times based on the conversion mode that is selected. 2. when sampling is completed, the converter is isolated from the input channel and a successive approximation algorithm is applied to determine the digital value of the analog signal. 3. the result of the conversion is transferred to rn upon completion of the conversion algorithm. if the bus frequency is less than f adck , precise sample time for continuous conversions cannot be guaranteed when short sample is enabled, that is, when cfg1[adlsmp]=0. the maximum total conversion time is determined by the clock source chosen and the divide ratio selected. the clock source is selectable by cfg1[adiclk], and the divide ratio is specified by cfg1[adiv]. the maximum total conversion time for all configurations is summarized in the equation below. see the following tables for the variables referenced in the equation. figure 28-46. conversion time equation table 28-54. single or first continuous time adder (sfcadder) cfg1[ad lsmp] cfg2[ad acken] cfg1[adiclk] single or first continuous time adder (sfcadder) 1 x 0x, 10 3 adck cycles + 5 bus clock cycles 1 1 11 3 adck cycles + 5 bus clock cycles 1 1 0 11 5 s + 3 adck cycles + 5 bus clock cycles 0 x 0x, 10 5 adck cycles + 5 bus clock cycles 0 1 11 5 adck cycles + 5 bus clock cycles 1 0 0 11 5 s + 5 adck cycles + 5 bus clock cycles 1. to achieve this time, cfg2[adacken] must be 1 for at least 5 s prior to the conversion is initiated. table 28-55. average number factor (averagenum) sc3[avge] sc3[avgs] average number factor (averagenum) 0 xx 1 table continues on the next page... functional description kl04 sub-family reference manual, rev. 3.1, november 2012 444 freescale semiconductor, inc.
table 28-55. average number factor (averagenum) (continued) sc3[avge] sc3[avgs] average number factor (averagenum) 1 00 4 1 01 8 1 10 16 1 11 32 table 28-56. base conversion time (bct) mode base conversion time (bct) 8b single-ended 17 adck cycles 10b single-ended 20 adck cycles 12b single-ended 20 adck cycles table 28-57. long sample time adder (lstadder) cfg1[adlsmp] cfg2[adlsts] long sample time adder (lstadder) 0 xx 0 adck cycles 1 00 20 adck cycles 1 01 12 adck cycles 1 10 6 adck cycles 1 11 2 adck cycles table 28-58. high-speed conversion time adder (hscadder) cfg2[adhsc] high-speed conversion time adder (hscadder) 0 0 adck cycles 1 2 adck cycles note the adck frequency must be between f adck minimum and f adck maximum to meet adc specifications. 28.4.4.6 conversion time examples the following examples use the figure 28-46 , and the information provided in table 28-54 through table 28-58 . chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 445
28.4.4.6.1 typical conversion time configuration a typical configuration for adc conversion is: ? 10-bit mode, with the bus clock selected as the input clock source ? the input clock divide-by-1 ratio selected ? bus frequency of 8 mhz ? long sample time disabled ? high-speed conversion disabled the conversion time for a single conversion is calculated by using the figure 28-46 , and the information provided in table 28-54 through table 28-58 . the table below lists the variables of figure 28-46 . table 28-59. typical conversion time variable time sfcadder 5 adck cycles + 5 bus clock cycles averagenum 1 bct 20 adck cycles lstadder 0 hscadder 0 the resulting conversion time is generated using the parameters listed in the preceding table. therefore, for a bus clock and an adck frequency equal to 8 mhz, the resulting conversion time is 3.75 s. 28.4.4.6.2 short conversion time configuration a configuration for short adc conversion is: ? 8-bit single-ended mode with the bus clock selected as the input clock source ? the input clock divide-by-1 ratio selected ? bus frequency of 20 mhz ? long sample time disabled ? high-speed conversion enabled the conversion time for this conversion is calculated by using the figure 28-46 , and the information provided in table 28-54 through table 28-58 . the table below lists the variables of figure 28-46 . table 28-60. typical conversion time variable time sfcadder 5 adck cycles + 5 bus clock cycles averagenum 1 bct 17 adck cycles table continues on the next page... functional description kl04 sub-family reference manual, rev. 3.1, november 2012 446 freescale semiconductor, inc.
table 28-60. typical conversion time (continued) variable time lstadder 0 adck cycles hscadder 2 the resulting conversion time is generated using the parameters listed in in the preceding table. therefore, for bus clock and adck frequency equal to 20 mhz, the resulting conversion time is 1.45 s. 28.4.4.7 hardware average function the hardware average function can be enabled by setting sc3[avge]=1 to perform a hardware average of multiple conversions. the number of conversions is determined by the avgs[1:0] bits, which can select 4, 8, 16, or 32 conversions to be averaged. while the hardware average function is in progress, sc2[adact] will be set. after the selected input is sampled and converted, the result is placed in an accumulator from which an average is calculated once the selected number of conversions have been completed. when hardware averaging is selected, the completion of a single conversion will not set sc1n[coco]. if the compare function is either disabled or evaluates true, after the selected number of conversions are completed, the average conversion result is transferred into the data result registers, rn, and sc1n[coco] is set. an adc interrupt is generated upon the setting of sc1n[coco] if the respective adc interrupt is enabled, that is, sc1n[aien]=1. note the hardware average function can perform conversions on a channel while the mcu is in wait or normal stop modes. the adc interrupt wakes the mcu when the hardware average is completed if sc1n[aien] was set. 28.4.5 automatic compare function the compare function can be configured to check whether the result is less than or greater-than-or-equal-to a single compare value, or, if the result falls within or outside a range determined by two compare values. the compare mode is determined by sc2[acfgt], sc2[acren], and the values in the compare value registers, cv1 and chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 447
cv2. after the input is sampled and converted, the compare values in cv1 and cv2 are used as described in the following table. there are six compare modes as shown in the following table. table 28-61. compare modes sc2[ac fgt] sc2[ac ren] adccv1 relative to adccv2 function compare mode description 0 0 less than threshold compare true if the result is less than the cv1 registers. 1 0 greater than or equal to threshold compare true if the result is greater than or equal to cv1 registers. 0 1 less than or equal outside range, not inclusive compare true if the result is less than cv1 or the result is greater than cv2. 0 1 greater than inside range, not inclusive compare true if the result is less than cv1 and the result is greater than cv2. 1 1 less than or equal inside range, inclusive compare true if the result is greater than or equal to cv1 and the result is less than or equal to cv2. 1 1 greater than outside range, inclusive compare true if the result is greater than or equal to cv1 or the result is less than or equal to cv2. with sc2[acren] =1, and if the value of cv1 is less than or equal to the value of cv2, then setting sc2[acfgt] will select a trigger-if-inside-compare-range inclusive-of- endpoints function. clearing sc2[acfgt] will select a trigger-if-outside-compare- range, not-inclusive-of-endpoints function. if cv1 is greater than cv2, setting sc2[acfgt] will select a trigger-if-outside- compare-range, inclusive-of-endpoints function. clearing sc2[acfgt] will select a trigger-if-inside-compare-range, not-inclusive-of-endpoints function. if the condition selected evaluates true, sc1n[coco] is set. upon completion of a conversion while the compare function is enabled, if the compare condition is not true, sc1n[coco] is not set and the conversion result data will not be transferred to the result register, rn. if the hardware averaging function is enabled, the compare function compares the averaged result to the compare values. the same compare function definitions apply. an adc interrupt is generated when sc1n[coco] is set and the respective adc interrupt is enabled, that is, sc1n[aien]=1. note the compare function can monitor the voltage on a channel while the mcu is in wait or normal stop modes. the adc interrupt wakes the mcu when the compare condition is met. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 448 freescale semiconductor, inc.
28.4.6 calibration function the adc contains a self-calibration function that is required to achieve the specified accuracy. calibration must be run, or valid calibration values written, after any reset and before a conversion is initiated. the calibration function sets the offset calibration value and the plus-side calibration values. the offset calibration value is automatically stored in the adc offset correction register (ofs), and the plus-side calibration values are automatically stored in the adc plus-side calibration registers, clpx. the user must configure the adc correctly prior to calibration, and must generate the plus-side gain calibration results and store them in the adc plus-side gain register (pg) after the calibration function completes. prior to calibration, the user must configure the adc's clock source and frequency, low power configuration, voltage reference selection, sample time, and high speed configuration according to the application's clock source availability and needs. if the application uses the adc in a wide variety of configurations, the configuration for which the highest accuracy is required should be selected, or multiple calibrations can be done for the different configurations. for best calibration results: ? set hardware averaging to maximum, that is, sc3[avge]=1 and sc3[avgs]=11 for an average of 32 ? set adc clock frequency f adck less than or equal to 4 mhz ? v refh =v dda ? calibrate at nominal voltage and temperature the input channel, conversion mode continuous function, compare function, resolution mode, and single-ended mode are all ignored during the calibration function. to initiate calibration, the user sets sc3[cal] and the calibration will automatically begin if the sc2[adtrg] is 0. if sc2[adtrg] is 1, sc3[cal] will not get set and sc3[calf] will be set. while calibration is active, no adc register can be written and no stop mode may be entered, or the calibration routine will be aborted causing sc3[cal] to clear and sc3[calf] to set. at the end of a calibration sequence, sc1n[coco] will be set. sc1n[aien] can be used to allow an interrupt to occur at the end of a calibration sequence. at the end of the calibration routine, if sc3[calf] is not set, the automatic calibration routine is completed successfully. to complete calibration, the user must generate the gain calibration values using the following procedure: 1. initialize or clear a 16-bit variable in ram. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 449
2. add the plus-side calibration results clp0, clp1, clp2, clp3, clp4, and clps to the variable. 3. divide the variable by two. 4. set the msb of the variable. 5. the previous two steps can be achieved by setting the carry bit, rotating to the right through the carry bit on the high byte and again on the low byte. 6. store the value in the plus-side gain calibration register pg. when calibration is complete, the user may reconfigure and use the adc as desired. a second calibration may also be performed, if desired, by clearing and again setting sc3[cal]. overall, the calibration routine may take as many as 14k adck cycles and 100 bus cycles, depending on the results and the clock source chosen. for an 8 mhz clock source, this length amounts to about 1.7 ms. to reduce this latency, the calibration values, which are offset, plus-side gain, and plus-side calibration values, may be stored in flash memory after an initial calibration and recovered prior to the first adc conversion. this method can reduce the calibration latency to 20 register store operations on all subsequent power, reset, or low-power stop mode recoveries. 28.4.7 user-defined offset function ofs contains the user-selected or calibration-generated offset error correction value. this register is a 2s complement, left-justified. the value in ofs is subtracted from the conversion and the result is transferred into the result registers, rn. if the result is greater than the maximum or less than the minimum result value, it is forced to the appropriate limit for the current mode of operation. the formatting of the ofs is different from the data result register, rn, to preserve the resolution of the calibration value regardless of the conversion mode selected. lower order bits are ignored in lower resolution modes. for example, in 8-bit single-ended mode, ofs[14:7] are subtracted from d[7:0]; ofs[15] indicates the sign (negative numbers are effectively added to the result) and ofs[6:0] are ignored. ofs is automatically set according to calibration requirements once the self-calibration sequence is done, that is, sc3[cal] is cleared. the user may write to ofs to override the calibration result if desired. if the ofs is written by the user to a value that is different from the calibration value, the adc error specifications may not be met. storing the value generated by the calibration function in memory before overwriting with a user- specified value is recommended. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 450 freescale semiconductor, inc.
note there is an effective limit to the values of offset that can be set by the user. if the magnitude of the offset is too high, the results of the conversions will cap off at the limits. the offset calibration function may be employed by the user to remove application offsets or dc bias values. ofs may be written with a number in 2's complement format and this offset will be subtracted from the result, or hardware averaged value. to add an offset, store the negative offset in 2's complement format and the effect will be an addition. an offset correction that results in an out-of-range value will be forced to the minimum or maximum value. the minimum value for single-ended conversions is 0x0000. to preserve accuracy, the calibrated offset value initially stored in ofs must be added to the user-defined offset. for applications that may change the offset repeatedly during operation, store the initial offset calibration value in flash so it can be recovered and added to any user offset adjustment value and the sum stored in ofs. 28.4.8 temperature sensor the adc module includes a temperature sensor whose output is connected to one of the adc analog channel inputs. the following equation provides an approximate transfer function of the temperature sensor. m figure 28-47. approximate transfer function of the temperature sensor where: ? v temp is the voltage of the temperature sensor channel at the ambient temperature. ? v temp25 is the voltage of the temperature sensor channel at 25 c. ? m is referred as temperature sensor slope in the device data sheet. it is the hot or cold voltage versus temperature slope in v/c. for temperature calculations, use the v temp25 and temperature sensor slope values from the adc electricals table. in application code, the user reads the temperature sensor channel, calculates v temp , and compares to v temp25 . if v temp is greater than v temp25 the cold slope value is applied in the preceding equation. if v temp is less than v temp25 , the hot slope value is applied in chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 451
the preceding equation. adc electricals table may only specify one temperature sensor slope value. in that case, the user could use the same slope for the calculation across the operational temperature range. for more information on using the temperature sensor, see the application note titled temperature sensor for the hcs08 microcontroller family (document an3031). 28.4.9 mcu wait mode operation wait mode is a lower-power consumption standby mode from which recovery is fast because the clock sources remain active. if a conversion is in progress when the mcu enters wait mode, it continues until completion. conversions can be initiated while the mcu is in wait mode by means of the hardware trigger or if continuous conversions are enabled. the bus clock, bus clock divided by two, and adack are available as conversion clock sources while in wait mode. the use of altclk as the conversion clock source in wait is dependent on the definition of altclk for this mcu. see the chip configuration information on altclk specific to this mcu. if the compare and hardware averaging functions are disabled, a conversion complete event sets sc1n[coco] and generates an adc interrupt to wake the mcu from wait mode if the respective adc interrupt is enabled, that is, when sc1n[aien]=1. if the hardware averaging function is enabled, sc1n[coco] will set, and generate an interrupt if enabled, when the selected number of conversions are completed. if the compare function is enabled, sc1n[coco] will set, and generate an interrupt if enabled, only if the compare conditions are met. if a single conversion is selected and the compare trigger is not met, the adc will return to its idle state and cannot wake the mcu from wait mode unless a new conversion is initiated by the hardware trigger. 28.4.10 mcu normal stop mode operation stop mode is a low-power consumption standby mode during which most or all clock sources on the mcu are disabled. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 452 freescale semiconductor, inc.
28.4.10.1 normal stop mode with adack disabled if the asynchronous clock, adack, is not selected as the conversion clock, executing a stop instruction aborts the current conversion and places the adc in its idle state. the contents of the adc registers, including rn, are unaffected by normal stop mode. after exiting from normal stop mode, a software or hardware trigger is required to resume conversions. 28.4.10.2 normal stop mode with adack enabled if adack is selected as the conversion clock, the adc continues operation during normal stop mode. see the chip configuration chapter for configuration information for this mcu. if a conversion is in progress when the mcu enters normal stop mode, it continues until completion. conversions can be initiated while the mcu is in normal stop mode by means of the hardware trigger or if continuous conversions are enabled. if the compare and hardware averaging functions are disabled, a conversion complete event sets sc1n[coco] and generates an adc interrupt to wake the mcu from normal stop mode if the respective adc interrupt is enabled, that is, when sc1n[aien]=1. the result register, rn, will contain the data from the first completed conversion that occurred during normal stop mode. if the hardware averaging function is enabled, sc1n[coco] will set, and generate an interrupt if enabled, when the selected number of conversions are completed. if the compare function is enabled, sc1n[coco] will set, and generate an interrupt if enabled, only if the compare conditions are met. if a single conversion is selected and the compare is not true, the adc will return to its idle state and cannot wake the mcu from normal stop mode unless a new conversion is initiated by another hardware trigger. 28.4.11 mcu low-power stop mode operation the adc module is automatically disabled when the mcu enters low-power stop mode. all module registers contain their reset values following exit from low-power stop mode. therefore, the module must be re-enabled and re-configured following exit from low-power stop mode. note for the chip specific modes of operation, see the power management information for the device. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 453
28.5 initialization information this section gives an example that provides some basic direction on how to initialize and configure the adc module. the user can configure the module for 12-bit, 10-bit, or 8-bit single-ended resolution, single or continuous conversion, and a polled or interrupt approach, among many other options. for information used in this example, refer to table 28-57 , table 28-58 , and table 28-59 . note hexadecimal values are designated by a preceding 0x, binary values designated by a preceding %, and decimal values have no preceding character. 28.5.1 adc module initialization example 28.5.1.1 initialization sequence before the adc module can be used to complete conversions, an initialization procedure must be performed. a typical sequence is: 1. calibrate the adc by following the calibration instructions in calibration function . 2. update cfg to select the input clock source and the divide ratio used to generate adck. this register is also used for selecting sample time and low-power configuration. 3. update sc2 to select the conversion trigger, hardware or software, and compare function options, if enabled. 4. update sc3 to select whether conversions will be continuous or completed only once (adco) and whether to perform hardware averaging. 5. update sc1:sc1n registers to enable or disable conversion complete interrupts. also, select the input channel which can be used to perform conversions. initialization information kl04 sub-family reference manual, rev. 3.1, november 2012 454 freescale semiconductor, inc.
28.5.1.2 pseudo-code example in this example, the adc module is set up with interrupts enabled to perform a single 10- bit conversion at low-power with a long sample time on input channel 1, where adck is derived from the bus clock divided by 1. cfg1 = 0x98 (%10011000) bit 7 adlpc 1 configures for low power, lowers maximum clock speed. bit 6:5 adiv 00 sets the adck to the input clock 1. bit 4 adlsmp 1 configures for long sample time. bit 3:2 mode 10 selects the single-ended 10-bit conversion. bit 1:0 adiclk 00 selects the bus clock. sc2 = 0x00 (%00000000) bit 7 adact 0 flag indicates if a conversion is in progress. bit 6 adtrg 0 software trigger selected. bit 5 acfe 0 compare function disabled. bit 4 acfgt 0 not used in this example. bit 3 acren 0 compare range disabled. bit 2 dmaen 0 dma request disabled. bit 1:0 refsel 00 selects default voltage reference pin pair (external pins v refh and v refl ). sc1a = 0x41 (%01000001) bit 7 coco 0 read-only flag which is set when a conversion completes. bit 6 aien 1 conversion complete interrupt enabled. bit 4:0 adch 00001 input channel 1 selected as adc input channel. ra = 0xxx holds results of conversion. cv = 0xxx holds compare value when compare function enabled. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 455
reset no yes check sc1n[coco]=1? initialize adc cfg1 = 0x98 sc2 = 0x00 sc1n = 0x41 continue read rn to clear sc1n[coco] figure 28-48. initialization flowchart example 28.6 application information the adc has been designed to be integrated into a microcontroller for use in embedded control applications requiring an adc. 28.6.1 external pins and routing 28.6.1.1 analog supply pins depending on the device, the analog power and ground supplies, v dda and v ssa , of the adc module are available as: ? v dda and v ssa available as separate pinswhen available on a separate pin, both v dda and v ssa must be connected to the same voltage potential as their corresponding mcu digital supply, v dd and v ss , and must be routed carefully for maximum noise immunity and bypass capacitors placed as near as possible to the package. application information kl04 sub-family reference manual, rev. 3.1, november 2012 456 freescale semiconductor, inc.
? v ssa is shared on the same pin as the mcu digital v ss . ? v ssa and v dda are shared with the mcu digital supply pinsin these cases, there are separate pads for the analog supplies bonded to the same pin as the corresponding digital supply so that some degree of isolation between the supplies is maintained. if separate power supplies are used for analog and digital power, the ground connection between these supplies must be at the v ssa pin. this must be the only ground connection between these supplies, if possible. v ssa makes a good single point ground location. 28.6.1.2 analog voltage reference pins in addition to the analog supplies, the adc module has connections for two reference voltage inputs used by the converter: ? v refsh is the high reference voltage for the converter. ? v refsl is the low reference voltage for the converter. the adc can be configured to accept one of two voltage reference pairs for v refsh and v refsl . each pair contains a positive reference and a ground reference. the two pairs are external, v refh and v refl and alternate, v alth and v altl . these voltage references are selected using sc2[refsel]. the alternate voltage reference pair, v alth and v altl , may select additional external pins or internal sources based on mcu configuration. see the chip configuration information on the voltage references specific to this mcu. in some packages, the external or alternate pairs are connected in the package to v dda and v ssa , respectively. one of these positive references may be shared on the same pin as v dda on some devices. one of these ground references may be shared on the same pin as v ssa on some devices. if externally available, the positive reference may be connected to the same potential as v dda or may be driven by an external source to a level between the minimum ref voltage high and the v dda potential. the positive reference must never exceed v dda . if externally available, the ground reference must be connected to the same voltage potential as v ssa . the voltage reference pairs must be routed carefully for maximum noise immunity and bypass capacitors placed as near as possible to the package. ac current in the form of current spikes required to supply charge to the capacitor array at each successive approximation step is drawn through the v refh and v refl loop. the best external component to meet this current demand is a 0.1 f capacitor with good high-frequency characteristics. this capacitor is connected between v refh and v refl and must be placed as near as possible to the package pins. resistance in the path is not recommended because the current causes a voltage drop that could result in conversion errors. inductance in this path must be minimum, that is, parasitic only. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 457
28.6.1.3 analog input pins the external analog inputs are typically shared with digital i/o pins on mcu devices. empirical data shows that capacitors on the analog inputs improve performance in the presence of noise or when the source impedance is high. use of 0.01 f capacitors with good high-frequency characteristics is sufficient. these capacitors are not necessary in all cases, but when used, they must be placed as near as possible to the package pins and be referenced to v ssa . for proper conversion, the input voltage must fall between v refh and v refl . if the input is equal to or exceeds v refh , the converter circuit converts the signal to 0xfff, which is full scale 12-bit representation, 0x3ff, which is full scale 10-bit representation, or 0xff, which is full scale 8-bit representation. if the input is equal to or less than v refl , the converter circuit converts it to 0x000. input voltages between v refh and v refl are straight-line linear conversions. there is a brief current associated with v refl when the sampling capacitor is charging. for minimal loss of accuracy due to current injection, pins adjacent to the analog input pins must not be transitioning during conversions. 28.6.2 sources of error 28.6.2.1 sampling error for proper conversions, the input must be sampled long enough to achieve the proper accuracy. ras + radin =sc / (fmax * numtau * cadin) figure 28-49. sampling equation where: ras = external analog source resistance sc = number of adck cycles used during sample window cadin = internal adc input capacitance numtau = -ln(lsberr / 2 n ) application information kl04 sub-family reference manual, rev. 3.1, november 2012 458 freescale semiconductor, inc.
lsberr = value of acceptable sampling error in lsbs n = 8 in 8-bit mode, 10 in 10-bit mode, 12 in 12-bit mode higher source resistances or higher-accuracy sampling is possible by setting cfg1[adlsmp] and changing cfg2[adlsts] to increase the sample window, or decreasing adck frequency to increase sample time. 28.6.2.2 pin leakage error leakage on the i/o pins can cause conversion error if the external analog source resistance, r as , is high. if this error cannot be tolerated by the application, keep r as lower than v refh / (4 i leak 2 n ) for less than 1/4 lsb leakage error, where n = 8 in 8-bit mode, 10 in 10-bit mode, 12 in 12-bit mode. 28.6.2.3 noise-induced errors system noise that occurs during the sample or conversion process can affect the accuracy of the conversion. the adc accuracy numbers are guaranteed as specified only if the following conditions are met: ? there is a 0.1 f low-esr capacitor from v refh to v refl . ? there is a 0.1 f low-esr capacitor from v dda to v ssa . ? if inductive isolation is used from the primary supply, an additional 1 f capacitor is placed from v dda to v ssa . ? v ssa , and v refl , if connected, is connected to v ss at a quiet point in the ground plane. ? operate the mcu in wait or normal stop mode before initiating (hardware-triggered conversions) or immediately after initiating (hardware- or software-triggered conversions) the adc conversion. ? for software triggered conversions, immediately follow the write to sc1 with a wait instruction or stop instruction. ? for normal stop mode operation, select adack as the clock source. operation in normal stop reduces v dd noise but increases effective conversion time due to stop recovery. ? there is no i/o switching, input or output, on the mcu during the conversion. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 459
there are some situations where external system activity causes radiated or conducted noise emissions or excessive v dd noise is coupled into the adc. in these situations, or when the mcu cannot be placed in wait or normal stop mode, or i/o activity cannot be halted, the following actions may reduce the effect of noise on the accuracy: ? place a 0.01 f capacitor (c as ) on the selected input channel to v refl or v ssa . this improves noise issues, but affects the sample rate based on the external analog source resistance. ? average the result by converting the analog input many times in succession and dividing the sum of the results. four samples are required to eliminate the effect of a 1 lsb, one-time error. ? reduce the effect of synchronous noise by operating off the asynchronous clock, that is, adack, and averaging. noise that is synchronous to adck cannot be averaged out. 28.6.2.4 code width and quantization error the adc quantizes the ideal straight-line transfer function into 4096 steps in the 12-bit mode). each step ideally has the same height, that is, 1 code, and width. the width is defined as the delta between the transition points to one code and the next. the ideal code width for an n-bit converter, where n can be 12, 10, or 8, defined as 1 lsb, is: lsb figure 28-50. ideal code width for an n-bit converter there is an inherent quantization error due to the digitization of the result. for 8-bit, 10- bit, or 12-bit conversions, the code transitions when the voltage is at the midpoint between the points where the straight line transfer function is exactly represented by the actual transfer function. therefore, the quantization error will be 1/2 lsb in 8-bit, 10- bit, or 12-bit modes. as a consequence, however, the code width of the first (0x000) conversion is only 1/2 lsb and the code width of the last (0xff or 0x3ff) is 1.5 lsb. 28.6.2.5 linearity errors the adc may also exhibit non-linearity of several forms. every effort has been made to reduce these errors, but the system designers must be aware of these errors because they affect overall accuracy: application information kl04 sub-family reference manual, rev. 3.1, november 2012 460 freescale semiconductor, inc.
? zero-scale error (e zs ), sometimes called offset: this error is defined as the difference between the actual code width of the first conversion and the ideal code width. this is 1/2 lsb in 8-bit, 10-bit, or 12-bit modes. if the first conversion is 0x001, the difference between the actual 0x001 code width and its ideal (1 lsb) is used. ? full-scale error (e fs ): this error is defined as the difference between the actual code width of the last conversion and the ideal code width. this is 1.5 lsb in 8-bit, 10-bit, or 12-bit modes. if the last conversion is 0x3fe, the difference between the actual 0x3fe code width and its ideal (1 lsb) is used. ? differential non-linearity (dnl): this error is defined as the worst-case difference between the actual code width and the ideal code width for all conversions. ? integral non-linearity (inl): this error is defined as the highest-value or absolute value that the running sum of dnl achieves. more simply, this is the worst-case difference of the actual transition voltage to a given code and its corresponding ideal transition voltage, for all codes. ? total unadjusted error (tue): this error is defined as the difference between the actual transfer function and the ideal straight-line transfer function and includes all forms of error. 28.6.2.6 code jitter, non-monotonicity, and missing codes analog-to-digital converters are susceptible to three special forms of error: ? code jitter: code jitter is when, at certain points, a given input voltage converts to one of the two values when sampled repeatedly. ideally, when the input voltage is infinitesimally smaller than the transition voltage, the converter yields the lower code, and vice-versa. however, even small amounts of system noise can cause the converter to be indeterminate, between two codes, for a range of input voltages around the transition voltage. this error may be reduced by repeatedly sampling the input and averaging the result. additionally, the techniques discussed in noise-induced errors reduces this error. ? non-monotonicity: non-monotonicity is defined as when, except for code jitter, the converter converts to a lower code for a higher input voltage. ? missing codes: missing codes are those values never converted for any input value. in 8-bit or 10-bit mode, the adc is guaranteed to be monotonic and have no missing codes. chapter 28 analog-to-digital converter (adc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 461
application information kl04 sub-family reference manual, rev. 3.1, november 2012 462 freescale semiconductor, inc.
chapter 29 comparator (cmp) 29.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the comparator (cmp) module provides a circuit for comparing two analog input voltages. the comparator circuit is designed to operate across the full range of the supply voltage, known as rail-to-rail operation. the analog mux (anmux) provides a circuit for selecting an analog input signal from eight channels. one signal is provided by the 6-bit digital-to-analog converter (dac). the mux circuit is designed to operate across the full range of the supply voltage. the 6-bit dac is 64-tap resistor ladder network which provides a selectable voltage reference for applications where voltage reference is needed. the 64-tap resistor ladder network divides the supply reference v in into 64 voltage levels. a 6-bit digital signal input selects the output voltage level, which varies from v in to v in /64. v in can be selected from two voltage sources, v in1 and v in2 . the 6-bit dac from a comparator is available as an on-chip internal signal only and is not available externally to a pin. 29.2 cmp features the cmp has the following features: ? operational over the entire supply range ? inputs may range from rail to rail ? programmable hysteresis control kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 463
? selectable interrupt on rising-edge, falling-edge, or both rising or falling edges of the comparator output ? selectable inversion on comparator output ? capability to produce a wide range of outputs such as: ? sampled ? windowed, which is ideal for certain pwm zero-crossing-detection applications ? digitally filtered: ? filter can be bypassed ? can be clocked via external sample signal or scaled bus clock ? external hysteresis can be used at the same time that the output filter is used for internal functions ? two software selectable performance levels: ? shorter propagation delay at the expense of higher power ? low power, with longer propagation delay ? dma transfer support ? a comparison event can be selected to trigger a dma transfer ? functional in all modes of operation ? the window and filter functions are not available in the following modes: ? stop ? vlps ? lls ? vllsx 29.3 6-bit dac key features ? 6-bit resolution ? selectable supply reference source ? power down mode to conserve power when not in use ? option to route the output to internal comparator input 6-bit dac key features kl04 sub-family reference manual, rev. 3.1, november 2012 464 freescale semiconductor, inc.
29.4 anmux key features ? two 8-to-1 channel mux ? operational over the entire supply range 29.5 cmp, dac and anmux diagram the following figure shows the block diagram for the high-speed comparator, dac, and anmux modules. chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 465
vrsel vosel[5:0] mux 64-level psel[2:0] dac mux mux irq anmux msel[2:0] cmp cmp mux dac output dacen v in1 v in2 window and filter control cmpo reference input 0 reference input 1 reference input 2 reference input 3 reference input 4 reference input 5 reference input 6 inp inm sample input figure 29-1. cmp, dac and anmux block diagram 29.6 cmp block diagram the following figure shows the block diagram for the cmp module. cmp block diagram kl04 sub-family reference manual, rev. 3.1, november 2012 466 freescale semiconductor, inc.
irq inp inm filter_cnt inv cout cout ope se cmpo to pad couta 1 we 0 se cgmux cos filt_per + - filt_per bus clock cos ier/f cfr/f window/sample 1 0 en,pmode,hysctrl[1:0] interrupt control filter block window control polarity select clock prescaler divided bus clock cmpo to other soc functions internal bus figure 29-2. comparator module block diagram in the cmp block diagram: ? the window control block is bypassed when cr1[we] = 0 ? if cr1[we] = 1, the comparator output will be sampled on every bus clock when window=1 to generate couta. sampling does not occur when window = 0. ? the filter block is bypassed when not in use. ? the filter block acts as a simple sampler if the filter is bypassed and cr0[filter_cnt] is set to 0x01. ? the filter block filters based on multiple samples when the filter is bypassed and cr0[filter_cnt] is set greater than 0x01. ? if cr1[se] = 1, the external sample input is used as sampling clock ? if cr1[se] = 0, the divided bus clock is used as sampling clock chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 467
? if enabled, the filter block will incur up to one bus clock additional latency penalty on cout due to the fact that cout, which is crossing clock domain boundaries, must be resynchronized to the bus clock. ? cr1[we] and cr1[se] are mutually exclusive. 29.7 memory map/register definitions cmp memory map absolute address (hex) register name width (in bits) access reset value section/ page 4007_3000 cmp control register 0 (cmp0_cr0) 8 r/w 00h 29.7.1/468 4007_3001 cmp control register 1 (cmp0_cr1) 8 r/w 00h 29.7.2/469 4007_3002 cmp filter period register (cmp0_fpr) 8 r/w 00h 29.7.3/471 4007_3003 cmp status and control register (cmp0_scr) 8 r/w 00h 29.7.4/471 4007_3004 dac control register (cmp0_daccr) 8 r/w 00h 29.7.5/472 4007_3005 mux control register (cmp0_muxcr) 8 r/w 00h 29.7.6/473 29.7.1 cmp control register 0 (cmp x _cr0) address: 4007_3000h base + 0h offset = 4007_3000h bit 7 6 5 4 3 2 1 0 read 0 filter_cnt 0 0 hystctr write reset 0 0 0 0 0 0 0 0 cmp x _cr0 field descriptions field description 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6C4 filter_cnt filter sample count represents the number of consecutive samples that must agree prior to the comparator ouput filter accepting a new output state. for information regarding filter programming and latency, see the functional description . 000 filter is disabled. if se = 1, then cout is a logic 0. this is not a legal state, and is not recommended. if se = 0, cout = couta. 001 one sample must agree. the comparator output is simply sampled. 010 2 consecutive samples must agree. 011 3 consecutive samples must agree. 100 4 consecutive samples must agree. table continues on the next page... memory map/register definitions kl04 sub-family reference manual, rev. 3.1, november 2012 468 freescale semiconductor, inc.
cmp x _cr0 field descriptions (continued) field description 101 5 consecutive samples must agree. 110 6 consecutive samples must agree. 111 7 consecutive samples must agree. 3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1C0 hystctr comparator hard block hysteresis control defines the programmable hysteresis level. the hysteresis values associated with each level are device- specific. see the data sheet of the device for the exact values. 00 level 0 01 level 1 10 level 2 11 level 3 29.7.2 cmp control register 1 (cmp x _cr1) address: 4007_3000h base + 1h offset = 4007_3001h bit 7 6 5 4 3 2 1 0 read se we trigm pmode inv cos ope en write reset 0 0 0 0 0 0 0 0 cmp x _cr1 field descriptions field description 7 se sample enable at any given time, either se or we can be set. it is mandatory request to not set se and we both at a given time. 0 sampling mode is not selected. 1 sampling mode is selected. 6 we windowing enable at any given time, either se or we can be set. it is mandatory request to not set se and we both at a given time. 0 windowing mode is not selected. 1 windowing mode is selected. 5 trigm trigger mode enable cmp and dac are configured to cmp trigger mode when cmp_cr1[trigm] is set to 1. in addition, the cmp should be enabled. if the dac is to be used as a reference to the cmp, it should also be enabled. table continues on the next page... chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 469
cmp x _cr1 field descriptions (continued) field description cmp trigger mode depends on an external timer resource to periodically enable the cmp and 6-bit dac in order to generate a triggered compare. upon setting trigm, the cmp and dac are placed in a standby state until an external timer resource trigger is received. see the chip configuration chapter for details about the external timer resource. 0 trigger mode is disabled. 1 trigger mode is enabled. 4 pmode power mode select see the electrical specifications table in the device data sheet for details. 0 low-speed (ls) comparison mode selected. in this mode, cmp has slower output propagation delay and lower current consumption. 1 high-speed (hs) comparison mode selected. in this mode, cmp has faster output propagation delay and higher current consumption. 3 inv comparator invert allows selection of the polarity of the analog comparator function. it is also driven to the cout output, on both the device pin and as scr[cout], when ope=0. 0 does not invert the comparator output. 1 inverts the comparator output. 2 cos comparator output select 0 set the filtered comparator output (cmpo) to equal cout. 1 set the unfiltered comparator output (cmpo) to equal couta. 1 ope comparator output pin enable 0 cmpo is not available on the associated cmpo output pin. if the comparator does not own the pin, this field has no effect. 1 cmpo is available on the associated cmpo output pin. the comparator output (cmpo) is driven out on the associated cmpo output pin if the comparator owns the pin. if the comparator does not own the field, this bit has no effect. 0 en comparator module enable enables the analog comparator module. when the module is not enabled, it remains in the off state, and consumes no power. when the user selects the same input from analog mux to the positive and negative port, the comparator is disabled automatically. 0 analog comparator is disabled. 1 analog comparator is enabled. memory map/register definitions kl04 sub-family reference manual, rev. 3.1, november 2012 470 freescale semiconductor, inc.
29.7.3 cmp filter period register (cmp x _fpr) address: 4007_3000h base + 2h offset = 4007_3002h bit 7 6 5 4 3 2 1 0 read filt_per write reset 0 0 0 0 0 0 0 0 cmp x _fpr field descriptions field description 7C0 filt_per filter sample period specifies the sampling period, in bus clock cycles, of the comparator output filter, when cr1[se]=0. setting filt_per to 0x0 disables the filter. filter programming and latency details appear in the functional description . this field has no effect when cr1[se]=1. in that case, the external sample signal is used to determine the sampling period. 29.7.4 cmp status and control register (cmp x _scr) address: 4007_3000h base + 3h offset = 4007_3003h bit 7 6 5 4 3 2 1 0 read 0 dmaen 0 ier ief cfr cff cout write w1c w1c reset 0 0 0 0 0 0 0 0 cmp x _scr field descriptions field description 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6 dmaen dma enable control enables the dma transfer triggered from the cmp module. when this field is set, a dma request is asserted when cfr or cff is set. 0 dma is disabled. 1 dma is enabled. 5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4 ier comparator interrupt enable rising enables the cfr interrupt from the cmp. when this field is set, an interrupt will be asserted when cfr is set. table continues on the next page... chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 471
cmp x _scr field descriptions (continued) field description 0 interrupt is disabled. 1 interrupt is enabled. 3 ief comparator interrupt enable falling enables the cff interrupt from the cmp. when this field is set, an interrupt will be asserted when cff is set. 0 interrupt is disabled. 1 interrupt is enabled. 2 cfr analog comparator flag rising detects a rising-edge on cout, when set, during normal operation. cfr is cleared by writing 1 to it. during stop modes, cfr is level sensitive . 0 rising-edge on cout has not been detected. 1 rising-edge on cout has occurred. 1 cff analog comparator flag falling detects a falling-edge on cout, when set, during normal operation. cff is cleared by writing 1 to it. during stop modes, cff is level senstive . 0 falling-edge on cout has not been detected. 1 falling-edge on cout has occurred. 0 cout analog comparator output returns the current value of the analog comparator output, when read. the field is reset to 0 and will read as cr1[inv] when the analog comparator module is disabled, that is, when cr1[en] = 0. writes to this field are ignored. 29.7.5 dac control register (cmp x _daccr) address: 4007_3000h base + 4h offset = 4007_3004h bit 7 6 5 4 3 2 1 0 read dacen vrsel vosel write reset 0 0 0 0 0 0 0 0 cmp x _daccr field descriptions field description 7 dacen dac enable enables the dac. when the dac is disabled, it is powered down to conserve power. 0 dac is disabled. 1 dac is enabled. 6 vrsel supply voltage reference source select table continues on the next page... memory map/register definitions kl04 sub-family reference manual, rev. 3.1, november 2012 472 freescale semiconductor, inc.
cmp x _daccr field descriptions (continued) field description 0 v is selected as resistor ladder network supply reference v. in1in 1 v is selected as resistor ladder network supply reference v. in2in 5C0 vosel dac output voltage select selects an output voltage from one of 64 distinct levels. daco = (v in /64) * (vosel[5:0] + 1) , so the daco range is from v in /64 to v in . 29.7.6 mux control register (cmp x _muxcr) address: 4007_3000h base + 5h offset = 4007_3005h bit 7 6 5 4 3 2 1 0 read reserved 0 psel msel write reset 0 0 0 0 0 0 0 0 cmp x _muxcr field descriptions field description 7 reserved bit can be programmed to zero only . this field is reserved. 6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5C3 psel plus input mux control determines which input is selected for the plus input of the comparator. for inx inputs, see cmp, dac, and anmux block diagrams. note: when an inappropriate operation selects the same input for both muxes, the comparator automatically shuts down to prevent itself from becoming a noise generator. 000 in0 001 in1 010 in2 011 in3 100 in4 101 in5 110 in6 111 in7 2C0 msel minus input mux control determines which input is selected for the minus input of the comparator. for inx inputs, see cmp, dac, and anmux block diagrams. note: when an inappropriate operation selects the same input for both muxes, the comparator automatically shuts down to prevent itself from becoming a noise generator. 000 in0 table continues on the next page... chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 473
cmp x _muxcr field descriptions (continued) field description 001 in1 010 in2 011 in3 100 in4 101 in5 110 in6 111 in7 29.8 functional description the cmp module can be used to compare two analog input voltages applied to inp and inm. cmpo is high when the non-inverting input is greater than the inverting input, and is low when the non-inverting input is less than the inverting input. this signal can be selectively inverted by setting cr1[inv] = 1. scr[ier] and scr[ief] are used to select the condition which will cause the cmp module to assert an interrupt to the processor. scr[cff] is set on a falling-edge and scr[cfr] is set on rising-edge of the comparator output. the optionally filtered cmpo can be read directly through scr[cout]. 29.8.1 cmp functional modes there are three main sub-blocks to the cmp module: ? the comparator itself ? the window function ? the filter function the filter, cr0[filter_cnt], can be clocked from an internal or external clock source. the filter is programmable with respect to the number of samples that must agree before a change in the output is registered. in the simplest case, only one sample must agree. in this case, the filter acts as a simple sampler. the external sample input is enabled using cr1[se]. when set, the output of the comparator is sampled only on rising edges of the sample input. the "windowing mode" is enabled by setting cr1[we]. when set, the comparator output is sampled only when window=1. this feature can be used to ignore the comparator output during time periods in which the input voltages are not valid. this is especially useful when implementing zero-crossing-detection for certain pwm applications. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 474 freescale semiconductor, inc.
the comparator filter and sampling features can be combined as shown in the following table. individual modes are discussed below. table 29-15. comparator sample/filter controls mode # cr1[en] cr1[we] cr1[se] cr0[filter_c nt] fpr[filt_per] operation 1 0 x x x x disabled see the disabled mode (# 1) . 2a 1 0 0 0x00 x continuous mode see the continuous mode (#s 2a & 2b) . 2b 1 0 0 x 0x00 3a 1 0 1 0x01 x sampled, non-filtered mode see the sampled, non-filtered mode (#s 3a & 3b) . 3b 1 0 0 0x01 > 0x00 4a 1 0 1 > 0x01 x sampled, filtered mode see the sampled, filtered mode (#s 4a & 4b) . 4b 1 0 0 > 0x01 > 0x00 5a 1 1 0 0x00 x windowed mode comparator output is sampled on every rising bus clock edge when sample=1 to generate couta. see the windowed mode (#s 5a & 5b) . 5b 1 1 0 x 0x00 6 1 1 0 0x01 0x01C0xff windowed/resampled mode comparator output is sampled on every rising bus clock edge when sample=1 to generate couta, which is then resampled on an interval determined by filt_per to generate cout. see the windowed/resampled mode (# 6) . 7 1 1 0 > 0x01 0x01C0xff windowed/filtered mode comparator output is sampled on every rising bus clock edge when sample=1 to generate couta, which is then resampled and filtered to generate cout. see the windowed/filtered mode (#7) . all other combinations of cr1[en], cr1[we], cr1[se], cr0[filter_cnt], and fpr[filt_per] are illegal. for cases where a comparator is used to drive a fault input, for example, for a motor- control module such as ftm, it must be configured to operate in continuous mode so that an external fault can immediately pass through the comparator to the target fault circuitry. chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 475
note filtering and sampling settings must be changed only after setting cr1[se]=0 and cr0[filter_cnt]=0x00. this resets the filter to a known state. 29.8.1.1 disabled mode (# 1) in disabled mode, the analog comparator is non-functional and consumes no power. cmpo is 0 in this mode. 29.8.1.2 continuous mode (#s 2a & 2b) irq internal bus inp inm filter_cnt inv cout cout ope se cmpo to pad couta 1 we 0 se cgmux cos filt_per 0 + - filt_per cos ier/f cfr/f window/sample 1 0 en,pmode,hystctr[1:0] divided bus clock cmpo bus clock to other system functions polarity select window contro l filter block interrupt control clock prescaler figure 29-15. comparator operation in continuous mode note see the chip configuration section for the source of sample/ window input. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 476 freescale semiconductor, inc.
the analog comparator block is powered and active. cmpo may be optionally inverted, but is not subject to external sampling or filtering. both window control and filter blocks are completely bypassed. scr[cout] is updated continuously. the path from comparator input pins to output pin is operating in combinational unclocked mode. cout and couta are identical. for control configurations which result in disabling the filter block, see the filter block bypass logic diagram. 29.8.1.3 sampled, non-filtered mode (#s 3a & 3b) + - irq inp inm filter_cnt inv cout cout ope se cmpo to pad couta 1 we 0 se=1 cgmux cos filt_per 1 0 + - filt_per cos 0x01 ier/f cfr/f window/sample 1 0 en,pmode,hystctr[1:0] divided bus clock cmpo bus clock internal bus polarity select window control filter block interrupt control to other soc functions clock prescaler figure 29-16. sampled, non-filtered (# 3a): sampling point externally driven in sampled, non-filtered mode, the analog comparator block is powered and active. the path from analog inputs to couta is combinational unclocked. windowing control is completely bypassed. couta is sampled whenever a rising-edge is detected on the filter block clock input. chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 477
the only difference in operation between sampled, non-filtered (# 3a) and sampled, non-filtered (# 3b) is in how the clock to the filter block is derived. in #3a, the clock to filter block is externally derived while in #3b, the clock to filter block is internally derived. the comparator filter has no other function than sample/hold of the comparator output in this mode (# 3b). irq inp inm filter_cnt inv cout cout ope se cmpo to pad couta 1 we 0 se=0 cgmux cos filt_per 0 0 + - filt_per cos 0x01 ier/f cfr/f window/sample 1 0 en,pmode,hystctr[1:0] divided bus clock cmpo bus clock internal bus polarity select window control filter block interrupt control to other soc functions clock prescaler figure 29-17. sampled, non-filtered (# 3b): sampling interval internally derived 29.8.1.4 sampled, filtered mode (#s 4a & 4b) in sampled, filtered mode, the analog comparator block is powered and active. the path from analog inputs to couta is combinational unclocked. windowing control is completely bypassed. couta is sampled whenever a rising edge is detected on the filter block clock input. the only difference in operation between sampled, non-filtered (# 3a) and sampled, filtered (# 4a) is that, now, cr0[filter_cnt]>1, which activates filter operation. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 478 freescale semiconductor, inc.
+ - irq inp inm filter_cnt inv cout cout ope se cmpo to pad couta 1 we 0 se=1 cgmux cos filt_per 1 0 + - filt_per bus clock cos > ier/f cfr/f window/sample 1 0 en, pmode, hystctr[1:0] divided bus clock cmpo 0x01 internal bus polarity select window control filter block interrupt control clock prescaler to other soc functions figure 29-18. sampled, filtered (# 4a): sampling point externally driven chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 479
+ - irq inp inm filter_cnt inv cout cout ope se cmpo to pad couta 0 1 we 1 0 se=0 cgmux cos filt_per 0 0 + - filt_per bus clock cos > ier/f cfr/f window/sample en, pmode,hystctr[1:0 ] divided bus clock cmpo 0x01 internal bus polarity select window control filter block interrupt control clock prescaler to other soc functions figure 29-19. sampled, filtered (# 4b): sampling point internally derived the only difference in operation between sampled, non-filtered (# 3b) and sampled, filtered (# 4b) is that now, cr0[filter_cnt]>1, which activates filter operation. 29.8.1.5 windowed mode (#s 5a & 5b) the following figure illustrates comparator operation in the windowed mode, ignoring latency of the analog comparator, polarity select, and window control block. it also assumes that the polarity select is set to non-inverting state. note the analog comparator output is passed to couta only when the window signal is high. in actual operation, couta may lag the analog inputs by up to one bus clock cycle plus the combinational path delay through the comparator and polarity select logic. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 480 freescale semiconductor, inc.
wi ndow couta cmpo minus input plus input figure 29-20. windowed mode operation + - irq en, pmode,hysctr[1:0] inp inm filter_cnt inv cout cout ope se cmpo to pad couta 0 1 we 1 0 se=0 cgmux cos filt_per 0 + - filt_per bus clock cos 0x01 ier/f cfr/f window/sample polarity select window control filter block interrupt control divided bus clock clock prescaler cmpo internal bus to other soc functions figure 29-21. windowed mode for control configurations which result in disabling the filter block, see filter block bypass logic diagram. chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 481
when any windowed mode is active, couta is clocked by the bus clock whenever window = 1. the last latched value is held when window = 0. 29.8.1.6 windowed/resampled mode (# 6) the following figure uses the same input stimulus shown in figure 29-20 , and adds resampling of couta to generate cout. samples are taken at the time points indicated by the arrows in the figure. again, prop delays and latency are ignored for the sake of clarity. this example was generated solely to demonstrate operation of the comparator in windowed/resampled mode, and does not reflect any specific application. depending upon the sampling rate and window placement, cout may not see zero-crossing events detected by the analog comparator. sampling period and/or window placement must be carefully considered for a given application. wi ndow couta cout cmpo minus input plus input figure 29-22. windowed/resampled mode operation this mode of operation results in an unfiltered string of comparator samples where the interval between the samples is determined by fpr[filt_per] and the bus clock rate. configuration for this mode is virtually identical to that for the windowed/filtered mode shown in the next section. the only difference is that the value of cr0[filter_cnt] must be 1. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 482 freescale semiconductor, inc.
29.8.1.7 windowed/filtered mode (#7) this is the most complex mode of operation for the comparator block, as it uses both windowing and filtering features. it also has the highest latency of any of the modes. this can be approximated: up to 1 bus clock synchronization in the window function + ((cr0[filter_cnt] * fpr[filt_per]) + 1) * bus clock for the filter function. when any windowed mode is active, couta is clocked by the bus clock whenever window = 1. the last latched value is held when window = 0. + - irq en, pmode,hysctr[1:0] inp inm filter_cnt inv cout cout ope se cmpo to pad couta 0 1 we 1 0 se=0 cgmux cos filt_per 01 + - filt_per bus clock cos > ier/f cfr/f window/sample polarity select window control filter block interrupt control divided bus clock clock prescaler cmpo 0x01 to other soc functions internal bus figure 29-23. windowed/filtered mode 29.8.2 power modes 29.8.2.1 wait mode operation during wait and vlpw modes, the cmp, if enabled, continues to operate normally and a cmp interrupt can wake the mcu. chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 483
29.8.2.2 stop mode operation depending on clock restrictions related to the mcu core or core peripherals, the mcu is brought out of stop when a compare event occurs and the corresponding interrupt is enabled. similarly, if cr1[ope] is enabled, the comparator output operates as in the normal operating mode and comparator output is placed onto the external pin. in stop modes, the comparator can be operational in both: ? high-speed (hs) comparison mode when cr1[pmode] = 1 ? low-speed (ls) comparison mode when cr1[pmode] = 0 it is recommended to use the ls mode to minimize power consumption. if stop is exited with a reset, all comparator registers are put into their reset state. 29.8.2.3 background debug mode operation when the microcontroller is in active background debug mode, the cmp continues to operate normally. 29.8.3 startup and operation a typical startup sequence is as follows. the time required to stabilize cout will be the power-on delay of the comparators plus the largest propagation delay from a selected analog source through the analog comparator, windowing function and filter. see the data sheets for power-on delays of the comparators. the windowing function has a maximum of one bus clock period delay. the filter delay is specified in the low-pass filter . during operation, the propagation delay of the selected data paths must always be considered. it may take many bus clock cycles for cout and scr[cfr]/scr[cff] to reflect an input change or a configuration change to one of the components involved in the data path. when programmed for filtering modes, cout will initially be equal to 0, until sufficient clock cycles have elapsed to fill all stages of the filter. this occurs even if couta is at a logic 1. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 484 freescale semiconductor, inc.
29.8.4 low-pass filter the low-pass filter operates on the unfiltered and unsynchronized and optionally inverted comparator output couta and generates the filtered and synchronized output cout. both couta and cout can be configured as module outputs and are used for different purposes within the system. synchronization and edge detection are always used to determine status register bit values. they also apply to cout for all sampling and windowed modes. filtering can be performed using an internal timebase defined by fpr[filt_per], or using an external sample input to determine sample time. the need for digital filtering and the amount of filtering is dependent on user requirements. filtering can become more useful in the absence of an external hysteresis circuit. without external hysteresis, high-frequency oscillations can be generated at couta when the selected inm and inp input voltages differ by less than the offset voltage of the differential comparator. 29.8.4.1 enabling filter modes filter modes can be enabled by: ? setting cr0[filter_cnt] > 0x01 and ? setting fpr[filt_per] to a nonzero value or setting cr1[se]=1 if using the divided bus clock to drive the filter, it will take samples of couta every fpr[filt_per] bus clock cycles. the filter output will be at logic 0 when first initalized, and will subsequently change when all the consecutive cr0[filter_cnt] samples agree that the output value has changed. in other words, scr[cout] will be 0 for some initial period, even when couta is at logic 1. setting both cr1[se] and fpr[filt_per] to 0 disables the filter and eliminates switching current associated with the filtering process. note always switch to this setting prior to making any changes in filter parameters. this resets the filter to a known state. switching cr0[filter_cnt] on the fly without this intermediate step can result in unexpected behavior. chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 485
if cr1[se]=1, the filter takes samples of couta on each positive transition of the sample input. the output state of the filter changes when all the consecutive cr0[filter_cnt] samples agree that the output value has changed. 29.8.4.2 latency issues the value of fpr[filt_per] or sample period must be set such that the sampling period is just longer than the period of the expected noise. this way a noise spike will corrupt only one sample. the value of cr0[filter_cnt] must be chosen to reduce the probability of noisy samples causing an incorrect transition to be recognized. the probability of an incorrect transition is defined as the probability of an incorrect sample raised to the power of cr0[filter_cnt]. the values of fpr[filt_per] or sample period and cr0[filter_cnt] must also be traded off against the desire for minimal latency in recognizing actual comparator output transitions. the probability of detecting an actual output change within the nominal latency is the probability of a correct sample raised to the power of cr0[filter_cnt]. the following table summarizes maximum latency values for the various modes of operation in the absence of noise . filtering latency is restarted each time an actual output transition is masked by noise. table 29-16. comparator sample/filter maximum latencies mode # cr1[ en] cr1[ we] cr1[ se] cr0[filter _cnt] fpr[filt_p er] operation maximum latency 1 1 0 x x x x disabled n/a 2a 1 0 0 0x00 x continuous mode t pd 2b 1 0 0 x 0x00 3a 1 0 1 0x01 x sampled, non-filtered mode t pd + t sample + t per 3b 1 0 0 0x01 > 0x00 t pd + (fpr[filt_per] * t per ) + t per 4a 1 0 1 > 0x01 x sampled, filtered mode t pd + (cr0[filter_cnt] * t sample ) + t per 4b 1 0 0 > 0x01 > 0x00 t pd + (cr0[filter_cnt] * fpr[filt_per] x t per ) + t per 5a 1 1 0 0x00 x windowed mode t pd + t per 5b 1 1 0 x 0x00 t pd + t per 6 1 1 0 0x01 0x01 - 0xff windowed / resampled mode t pd + (fpr[filt_per] * t per ) + 2t per 7 1 1 0 > 0x01 0x01 - 0xff windowed / filtered mode t pd + (cr0[filter_cnt] * fpr[filt_per] x t per ) + 2t per functional description kl04 sub-family reference manual, rev. 3.1, november 2012 486 freescale semiconductor, inc.
1. t pd represents the intrinsic delay of the analog component plus the polarity select logic. t sample is the clock period of the external sample clock. t per is the period of the bus clock. 29.9 cmp interrupts the cmp module is capable of generating an interrupt on either the rising- or falling- edge of the comparator output, or both. the following table gives the conditions in which the interrupt request is asserted and deasserted. when then scr[ier] and scr[cfr] are set the interrupt request is asserted scr[ief] and scr[cff] are set the interrupt request is asserted scr[ier] and scr[cfr] are cleared for a rising-edge interrupt the interrupt request is deasserted scr[ief] and scr[cff] are cleared for a falling-edge interrupt the interrupt request is deasserted 29.10 dma support normally, the cmp generates a cpu interrupt if there is a change on the cout. when dma support is enabled by setting scr[dmaen] and the interrupt is enabled by setting scr[ier], scr[ief], or both, the corresponding change on cout forces a dma transfer request rather than a cpu interrupt instead. when the dma has completed the transfer, it sends a transfer completing indicator that deasserts the dma transfer request and clears the flag to allow a subsequent change on comparator output to occur and force another dma request. the comparator can remain functional in stop modes. when dma support is enabled by setting scr[dmaen] and the interrupt is enabled by setting scr[ier], scr[ief], or both, the corresponding change on cout forces a dma transfer request to wake up the system from stop modes. after the data transfer has finished, system will go back to stop modes. refer to dma chapters in the device reference manual for the asynchronous dma function for details. 29.11 cmp asyncrhonous dma support the comparator can remain functional in stop modes. when dma support is enabled by setting scr[dmaen] and the interrupt is enabled by setting scr[ier], scr[ief], or both, the corresponding change on cout forces a dma transfer request to wake up the chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 487
system from stop modes. after the data transfer has finished, system will go back to stop modes. refer to dma chapters in the device reference manual for the asynchronous dma function for details. 29.12 digital-to-analog converter the following figure shows the block diagram of the dac module. it contains a 64-tap resistor ladder network and a 64-to-1 multiplexer, which selects an output voltage from one of 64 distinct levels that outputs from daco. it is controlled through the dac control register (daccr). its supply reference source can be selected from two sources v in1 and v in2 . the module can be powered down or disabled when not in use. when in disabled mode, daco is connected to the analog ground. vosel[5:0] daco mux mux dacen vin vrsel v in1 v in2 figure 29-24. 6-bit dac block diagram 29.13 dac functional description this section provides dac functional description. digital-to-analog converter kl04 sub-family reference manual, rev. 3.1, november 2012 488 freescale semiconductor, inc.
29.13.1 voltage reference source select ? v in1 connects to the primary voltage source as supply reference of 64 tap resistor ladder ? v in2 connects to an alternate voltage source 29.14 dac resets this module has a single reset input, corresponding to the chip-wide peripheral reset. 29.15 dac clocks this module has a single clock input, the bus clock. 29.16 dac interrupts this module has no interrupts. 29.17 cmp trigger mode cmp and dac are configured to cmp trigger mode when cmp_cr1[trigm] is set to 1. in addition, the cmp must be enabled. if the dac is to be used as a reference to the cmp, it must also be enabled. cmp trigger mode depends on an external timer resource to periodically enable the cmp and 6-bit dac in order to generate a triggered compare. upon setting trigm, the cmp and dac are placed in a standby state until an external timer resource trigger is received. see the chip configuration chapter for details about the external timer resource. chapter 29 comparator (cmp) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 489
cmp trigger mode kl04 sub-family reference manual, rev. 3.1, november 2012 490 freescale semiconductor, inc.
chapter 30 timer/pwm module (tpm) 30.1 introduction the tpm (timer/pwm module) is a two to eight channel timer which supports input capture, output compare, and the generation of pwm signals to control electric motor and power management applications. the counter, compare and capture registers are clocked by an asynchronous clock that can remain enabled in low power modes. 30.1.1 tpm philosophy the tpm is built upon a very simple timer (hcs08 timer pwm module C tpm) used for many years on freescale's 8-bit microcontrollers. the tpm extends the functionality to support operation in low power modes by clocking the counter, compare and capture registers from an asynchronous clock that can remain functional in low power modes. 30.1.2 features the tpm features include: ? tpm clock mode is selectable ? can increment on every edge of the asynchronous counter clock ? can increment on rising edge of an external clock input synchronized to the asynchronous counter clock ? prescaler divide-by 1, 2, 4, 8, 16, 32, 64, or 128 ? tpm includes a 16-bit counter kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 491
? it can be a free-running counter or modulo counter ? the counting can be up or up-down ? includes 6 channels that can be configured for input capture, output compare, or edge-aligned pwm mode ? in input capture mode the capture can occur on rising edges, falling edges or both edges ? in output compare mode the output signal can be set, cleared, pulsed, or toggled on match ? all channels can be configured for center-aligned pwm mode ? support the generation of an interrupt and/or dma request per channel ? support the generation of an interrupt and/or dma request when the counter overflows ? support selectable trigger input to optionally reset or cause the counter to start incrementing. ? the counter can also optionally stop incrementing on counter overflow ? support the generation of hardware triggers when the counter overflows and per channel 30.1.3 modes of operation during debug mode, the tpm can can be configured to temporarily pause all counting until the core returns to normal user operating mode or to operate normally. when the counter is paused, trigger inputs and input capture events are ignored. during doze mode, the tpm can be configured to operate normally or to pause all counting for the duration of doze mode. when the counter is paused, trigger inputs and input capture events are ignored. during stop mode, the tpm counter clock can remain functional and the tpm can generate an asynchronous interrupt to exit the mcu from stop mode. 30.1.4 block diagram the tpm uses one input/output (i/o) pin per channel, chn (tpm channel (n)) where n is the channel number. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 492 freescale semiconductor, inc.
the following figure shows the tpm structure. the central component of the tpm is the 16-bit counter with programmable final value and its counting can be up or up-down. no clock selected (counter disable) module clock external clock cmod synchronizer cpwms ps toie tof mod module counter timer overflow interrupt channel 0 ms0b:ms0a els0b:els0a input capture mode logic channel 0 input c0v ch0ie ch0f channel 0 interrupt channel 0 output signal output modes logic prescaler channel n msnb:msna elsnb:elsna input capture mode logic channel n input cnv chnie chnf channel n interrupt channel n output signal output modes logic (generation of channel n outputs signals in output compare, epwm and cpwm modes) (generation of channel 0 outputs signals in output compare, epwm and cpwm modes) (1, 2, 4, 8, 16, 32, 64 or 128) 3 figure 30-1. tpm block diagram 30.2 tpm signal descriptions table 30-1 shows the user-accessible signals for the tpm. table 30-1. tpm signal descriptions signal description i/o tpm_extclk external clock. tpm external clock can be selected to increment the tpm counter on every rising edge synchronized to the counter clock. i tpm_chn tpm channel (n = 5 to 0) i/o chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 493
30.2.1 tpm_extclk tpm external clock the rising edge of the external input signal is used to increment the tpm counter if selected by cmod[1:0] bits in the sc register. this input signal must be less than half of the tpm counter clock frequency. the tpm counter prescaler selection and settings are also used when an external input is selected. 30.2.2 tpm_chn tpm channel (n) i/o pin each tpm channel can be configured to operate either as input or output. the direction associated with each channel, input or output, is selected according to the mode assigned for that channel. 30.3 memory map and register definition this section provides a detailed description of all tpm registers. attempting to access a reserved register location in the tpm memory map will generate a bus error. tpm memory map absolute address (hex) register name width (in bits) access reset value section/ page 4003_8000 status and control (tpm0_sc) 32 r/w 0000_0000h 30.3.1/496 4003_8004 counter (tpm0_cnt) 32 r/w 0000_0000h 30.3.2/497 4003_8008 modulo (tpm0_mod) 32 r/w 0000_ffffh 30.3.3/498 4003_800c channel (n) status and control (tpm0_c0sc) 32 r/w 0000_0000h 30.3.4/499 4003_8010 channel (n) value (tpm0_c0v) 32 r/w 0000_0000h 30.3.5/501 4003_8014 channel (n) status and control (tpm0_c1sc) 32 r/w 0000_0000h 30.3.4/499 4003_8018 channel (n) value (tpm0_c1v) 32 r/w 0000_0000h 30.3.5/501 4003_801c channel (n) status and control (tpm0_c2sc) 32 r/w 0000_0000h 30.3.4/499 4003_8020 channel (n) value (tpm0_c2v) 32 r/w 0000_0000h 30.3.5/501 4003_8024 channel (n) status and control (tpm0_c3sc) 32 r/w 0000_0000h 30.3.4/499 4003_8028 channel (n) value (tpm0_c3v) 32 r/w 0000_0000h 30.3.5/501 4003_802c channel (n) status and control (tpm0_c4sc) 32 r/w 0000_0000h 30.3.4/499 4003_8030 channel (n) value (tpm0_c4v) 32 r/w 0000_0000h 30.3.5/501 4003_8034 channel (n) status and control (tpm0_c5sc) 32 r/w 0000_0000h 30.3.4/499 4003_8038 channel (n) value (tpm0_c5v) 32 r/w 0000_0000h 30.3.5/501 4003_8050 capture and compare status (tpm0_status) 32 r/w 0000_0000h 30.3.6/501 4003_8084 configuration (tpm0_conf) 32 r/w 0000_0000h 30.3.7/503 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 494 freescale semiconductor, inc.
tpm memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page 4003_9000 status and control (tpm1_sc) 32 r/w 0000_0000h 30.3.1/496 4003_9004 counter (tpm1_cnt) 32 r/w 0000_0000h 30.3.2/497 4003_9008 modulo (tpm1_mod) 32 r/w 0000_ffffh 30.3.3/498 4003_900c channel (n) status and control (tpm1_c0sc) 32 r/w 0000_0000h 30.3.4/499 4003_9010 channel (n) value (tpm1_c0v) 32 r/w 0000_0000h 30.3.5/501 4003_9014 channel (n) status and control (tpm1_c1sc) 32 r/w 0000_0000h 30.3.4/499 4003_9018 channel (n) value (tpm1_c1v) 32 r/w 0000_0000h 30.3.5/501 4003_901c channel (n) status and control (tpm1_c2sc) 32 r/w 0000_0000h 30.3.4/499 4003_9020 channel (n) value (tpm1_c2v) 32 r/w 0000_0000h 30.3.5/501 4003_9024 channel (n) status and control (tpm1_c3sc) 32 r/w 0000_0000h 30.3.4/499 4003_9028 channel (n) value (tpm1_c3v) 32 r/w 0000_0000h 30.3.5/501 4003_902c channel (n) status and control (tpm1_c4sc) 32 r/w 0000_0000h 30.3.4/499 4003_9030 channel (n) value (tpm1_c4v) 32 r/w 0000_0000h 30.3.5/501 4003_9034 channel (n) status and control (tpm1_c5sc) 32 r/w 0000_0000h 30.3.4/499 4003_9038 channel (n) value (tpm1_c5v) 32 r/w 0000_0000h 30.3.5/501 4003_9050 capture and compare status (tpm1_status) 32 r/w 0000_0000h 30.3.6/501 4003_9084 configuration (tpm1_conf) 32 r/w 0000_0000h 30.3.7/503 chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 495
30.3.1 status and control (tpm x _sc) sc contains the overflow status flag and control bits used to configure the interrupt enable, module configuration and prescaler factor. these controls relate to all channels within this module. address: base address + 0h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 dma tof toie cpwms cmod ps w w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tpm x _sc field descriptions field description 31C9 reserved this field is reserved. this read-only field is reserved and always has the value 0. 8 dma dma enable enables dma transfers for the overflow flag. 0 disables dma transfers. 1 enables dma transfers. 7 tof timer overflow flag set by hardware when the lptpm counter equals the value in the mod register and increments. the tof bit is cleared by writing a 1 to tof bit. writing a 0 to tof has no effect. if another lptpm overflow occurs between the flag setting and the flag clearing, the write operation has no effect; therefore, tof remains set indicating another overflow has occurred. in this case a tof interrupt request is not lost due to a delay in clearing the previous tof. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 496 freescale semiconductor, inc.
tpm x _sc field descriptions (continued) field description 0 lptpm counter has not overflowed. 1 lptpm counter has overflowed. 6 toie timer overflow interrupt enable enables lptpm overflow interrupts. 0 disable tof interrupts. use software polling or dma request. 1 enable tof interrupts. an interrupt is generated when tof equals one. 5 cpwms center-aligned pwm select selects cpwm mode. this mode configures the lptpm to operate in up-down counting mode. this field is write protected. it can be written only when the counter is disabled. 0 lptpm counter operates in up counting mode. 1 lptpm counter operates in up-down counting mode. 4C3 cmod clock mode selection selects the lptpm counter clock modes. when disabling the counter, this field remain set until acknolwedged in the lptpm clock domain. 00 lptpm counter is disabled 01 lptpm counter increments on every lptpm counter clock 10 lptpm counter increments on rising edge of lptpm_extclk synchronized to the lptpm counter clock 11 reserved 2C0 ps prescale factor selection selects one of 8 division factors for the clock mode selected by cmod. this field is write protected. it can be written only when the counter is disabled. 000 divide by 1 001 divide by 2 010 divide by 4 011 divide by 8 100 divide by 16 101 divide by 32 110 divide by 64 111 divide by 128 30.3.2 counter (tpm x _cnt) the cnt register contains the lptpm counter value. reset clears the cnt register. writing any value to count also clears the counter. when debug is active, the lptpm counter does not increment unless configured otherwise. chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 497
reading the cnt register adds two wait states to the register access due to synchronization delays. address: base address + 4h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 count w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tpm x _cnt field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 count counter value 30.3.3 modulo (tpm x _mod) the modulo register contains the modulo value for the lptpm counter. when the lptpm counter reaches the modulo value and increments, the overflow flag (tof) is set and the next value of lptpm counter depends on the selected counting method (see counter ). writing to the mod register latches the value into a buffer. the mod register is updated with the value of its write buffer according to mod register update . it is recommended to initialize the lptpm counter (write to cnt) before writing to the mod register to avoid confusion about when the first counter overflow will occur. address: base address + 8h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 mod w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 tpm x _mod field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 mod modulo value when writing this field, all bytes must be written at the same time. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 498 freescale semiconductor, inc.
30.3.4 channel (n) status and control (tpm x _c n sc) cnsc contains the channel-interrupt-status flag and control bits used to configure the interrupt enable, channel configuration, and pin function. when switching from one channel mode to a different channel mode, the channel must first be disabled and this must be acknowledged in the lptpm counter clock domain. table 30-34. mode, edge, and level selection cpwms msnb:msna elsnb:elsna mode configuration x 00 00 none channel disabled x 01/10/11 00 software compare pin not used for lptpm 0 00 01 input capture capture on rising edge only 10 capture on falling edge only 11 capture on rising or falling edge 01 01 output compare toggle output on match 10 clear output on match 11 set output on match 10 10 edge-aligned pwm high-true pulses (clear output on match, set output on reload) x1 low-true pulses (set output on match, clear output on reload) 11 10 output compare pulse output low on match x1 pulse output high on match 1 10 10 center-aligned pwm high-true pulses (clear output on match-up, set output on match- down) x1 low-true pulses (set output on match-up, clear output on match- down) address: base address + ch offset + (8d i), where i=0d to 5d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 499
bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 chf chie msb msa elsb elsa 0 dma w w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tpm x _c n sc field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 chf channel flag set by hardware when an event occurs on the channel. chf is cleared by writing a 1 to the chf bit. writing a 0 to chf has no effect. if another event occurs between the chf sets and the write operation, the write operation has no effect; therefore, chf remains set indicating another event has occurred. in this case a chf interrupt request is not lost due to the delay in clearing the previous chf. 0 no channel event has occurred. 1 a channel event has occurred. 6 chie channel interrupt enable enables channel interrupts. 0 disable channel interrupts. 1 enable channel interrupts. 5 msb channel mode select used for further selections in the channel logic. its functionality is dependent on the channel mode. when a channel is disabled, this bit will not change state until acknowledged in the lptpm counter clock domain. 4 msa channel mode select used for further selections in the channel logic. its functionality is dependent on the channel mode. when a channel is disabled, this bit will not change state until acknowledged in the lptpm counter clock domain. 3 elsb edge or level select the functionality of elsb and elsa depends on the channel mode. when a channel is disabled, this bit will not change state until acknowledged in the lptpm counter clock domain. 2 elsa edge or level select the functionality of elsb and elsa depends on the channel mode. when a channel is disabled, this bit will not change state until acknowledged in the lptpm counter clock domain. 1 reserved this field is reserved. this read-only field is reserved and always has the value 0. 0 dma dma enable enables dma transfers for the channel. 0 disable dma transfers. 1 enable dma transfers. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 500 freescale semiconductor, inc.
30.3.5 channel (n) value (tpm x _c n v) these registers contain the captured lptpm counter value for the input modes or the match value for the output modes. in input capture mode, any write to a cnv register is ignored. in compare modes, writing to a cnv register latches the value into a buffer. a cnv register is updated with the value of its write buffer according to cnv register update . address: base address + 10h offset + (8d i), where i=0d to 5d bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 val w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tpm x _c n v field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 val channel value captured lptpm counter value of the input modes or the match value for the output modes. when writing this field, all bytes must be written at the same time. 30.3.6 capture and compare status (tpm x _status) the status register contains a copy of the status flag chnf bit (in cnsc) for each lptpm channel, as well as the tof bit (in sc), for software convenience. each chnf bit in status is a mirror of chnf bit in cnsc. all chnf bits can be checked using only one read of status. all chnf bits can be cleared by writing all ones to status. hardware sets the individual channel flags when an event occurs on the channel. chf is cleared by writing a 1 to the chf bit. writing a 0 to chf has no effect. if another event occurs between the flag setting and the write operation, the write operation has no effect; therefore, chf remains set indicating another event has occurred. in this case a chf interrupt request is not lost due to the clearing sequence for a previous chf. chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 501
address: base address + 50h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 tof 0 ch5f ch4f ch3f ch2f ch1f ch0f w w1c w1c w1c w1c w1c w1c w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tpm x _status field descriptions field description 31C9 reserved this field is reserved. this read-only field is reserved and always has the value 0. 8 tof timer overflow flag see register description 0 lptpm counter has not overflowed. 1 lptpm counter has overflowed. 7C6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5 ch5f channel 5 flag see the register description. 0 no channel event has occurred. 1 a channel event has occurred. 4 ch4f channel 4 flag see the register description. 0 no channel event has occurred. 1 a channel event has occurred. 3 ch3f channel 3 flag see the register description. 0 no channel event has occurred. 1 a channel event has occurred. table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 502 freescale semiconductor, inc.
tpm x _status field descriptions (continued) field description 2 ch2f channel 2 flag see the register description. 0 no channel event has occurred. 1 a channel event has occurred. 1 ch1f channel 1 flag see the register description. 0 no channel event has occurred. 1 a channel event has occurred. 0 ch0f channel 0 flag see the register description. 0 no channel event has occurred. 1 a channel event has occurred. 30.3.7 configuration (tpm x _conf) this register selects the behavior in debug and wait modes and the use of an external global time base. address: base address + 84h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 trgsel 0 crot csoo csot w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 gtbeen 0 dbgmode dozeen 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tpm x _conf field descriptions field description 31C28 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 503
tpm x _conf field descriptions (continued) field description 27C24 trgsel trigger select selects the input trigger to use for starting the counter and/or reloading the counter. this field should only be changed when the lptpm counter is disabled. see chip configuration section for available options. 23C19 reserved this field is reserved. this read-only field is reserved and always has the value 0. 18 crot counter reload on trigger when set, the lptpm counter will reload with zero (and initialize pwm outputs to their default value) when a rising edge is detected on the selected trigger input. the trigger input is ignored if the lptpm counter is paused during debug mode or doze mode. this field should only be changed when the lptpm counter is disabled. 0 counter is not reloaded due to a rising edge on the selected input trigger 1 counter is reloaded when a rising edge is detected on the selected input trigger 17 csoo counter stop on overflow when set, the lptpm counter will stop incrementing once the counter equals the mod value and incremented (this also sets the tof). reloading the counter with zero due to writing to the counter register or due to a trigger input does not cause the counter to stop incrementing. once the counter has stopped incrementing, the counter will not start incrementing unless it is disabled and then enabled again, or a rising edge on the selected trigger input is detected when csot set. this field should only be changed when the lptpm counter is disabled. 0 lptpm counter continues incrementing or decrementing after overflow 1 lptpm counter stops incrementing or decrementing after overflow. 16 csot counter start on trigger when set, the lptpm counter will not start incrementing after it is enabled until a rising edge on the selected trigger input is detected. if the lptpm counter is stopped due to an overflow, a rising edge on the selected trigger input will also cause the lptpm counter to start incrementing again. the trigger input is ignored if the lptpm counter is paused during debug mode or doze mode. this field should only be changed when the lptpm counter is disabled. 0 lptpm counter starts to increment immediately, once it is enabled. 1 lptpm counter only starts to increment when it a rising edge on the selected input trigger is detected, after it has been enabled or after it has stopped due to overflow. 15C10 reserved this field is reserved. this read-only field is reserved and always has the value 0. 9 gtbeen global time base enable configures the lptpm to use an externally generated global time base counter. when an externally generated timebase is used, the internal lptpm counter is not used by the channels but can be used to generate a periodic interrupt or dma request using the modulo register and timer overflow flag. 0 all channels use the internally generated lptpm counter as their timebase 1 all channels use an externally generated global timebase as their timebase 8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7C6 dbgmode debug mode table continues on the next page... memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 504 freescale semiconductor, inc.
tpm x _conf field descriptions (continued) field description configures the lptpm behavior in debug mode. all other configurations are reserved. 00 lptpm counter is paused and does not increment during debug mode. trigger inputs and input capture events are also ignored. 11 lptpm counter continues in debug mode. 5 dozeen doze enable configures the lptpm behavior in wait mode. 0 internal lptpm counter continues in doze mode. 1 internal lptpm counter is paused and does not increment during doze mode. trigger inputs and input capture events are also ignored. 4C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 30.4 functional description the following sections describe the tpm features. 30.4.1 clock domains the tpm module supports two clock domains. the bus clock domain is used by the register interface and for synchronizing interrupts and dma requests. the tpm counter clock domain is used to clock the counter and prescaler along with the output compare and input capture logic. the tpm counter clock is considered asynchronous to the bus clock, can be a higher or lower frequency than the bus clock and can remain operational in stop mode. multiple tpm instances are all clocked by the same tpm counter clock in support of the external timebase feature. 30.4.1.1 counter clock mode the cmod[1:0] bits in the sc register either disable the tpm counter or select one of two possible clock modes for the tpm counter. after any reset, cmod[1:0] = 0:0 so the tpm counter is disabled. chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 505
the cmod[1:0] bits may be read or written at any time. disabling the tpm counter by writing zero to the cmod[1:0] bits does not affect the tpm counter value or other registers, but must be acknowledged by the tpm counter clock domain before they read as zero. the external clock input passes through a synchronizer clocked by the tpm counter clock to assure that counter transitions are properly aligned to counter clock transitions. therefore, to meet nyquist criteria considering also jitter, the frequency of the external clock source must be less than half of the counter clock frequency. 30.4.2 prescaler the selected counter clock source passes through a prescaler that is a 7-bit counter. the value of the prescaler is selected by the ps[2:0] bits. the following figure shows an example of the prescaler counter and tpm counter. 0 0 0 0 0 0 0 0 00 0 0 1 1 1 2 2 3 3 1 1 1 1 11 1 1 1 selected input clock prescaler counter timer module counting is up. ps[2:0] = 001 cntin = 0x0000 timer module counter figure 30-59. example of the prescaler counter 30.4.3 counter the tpm has a 16-bit counter that is used by the channels either for input or output modes. the counter updates from the selected clock divided by the prescaler. the tpm counter has these modes of operation: ? up counting (see up counting ) ? up-down counting (see up-down counting ) 30.4.3.1 up counting up counting is selected when (cpwms = 0) functional description kl04 sub-family reference manual, rev. 3.1, november 2012 506 freescale semiconductor, inc.
the value of zero is loaded into the tpm counter, and the counter increments until the value of mod is reached, at which point the counter is reloaded with zero. the tpm period when using up counting is (mod + 0x0001) period of the tpm counter clock. the tof bit is set when the tpm counter changes from mod to zero. mod = 0x0004 tof bit 3 4 0 0 1 12 2 3 3 4 4 0 1 2 timer module counter set tof bit period of timer module counter clock period of counting = (mod + 0x0001) x period of timer module counter clock set tof bit set tof bit figure 30-60. example of tpm up counting note ? mod = 0000 is a redundant condition. in this case, the tpm counter is always equal to mod and the tof bit is set in each rising edge of the tpm counter clock. 30.4.3.2 up-down counting up-down counting is selected when (cpwms = 1). when configured for up-down counting, configuring mod to less than 2 is not supported. the value of zero is loaded into the tpm counter, and the counter increments until the value of mod is reached, at which point the counter is decremented until it returns to zero and the up-down counting restarts. the tpm period when using up-down counting is 2 mod period of the tpm counter clock. the tof bit is set when the tpm counter changes from mod to (mod C 1). chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 507
0 0 0 1 1 11 1 2 2 22 23 3 33 34 4 4 tof bit set tof bit set tof bit period of counting = 2 x mod x period of timer module counter clock mod = 0x0004 period of timer module counter clock timer module counter figure 30-61. example of up-down counting 30.4.3.3 counter reset any write to cnt resets the tpm counter and the channel outputs to their initial values (except for channels in output compare mode). 30.4.4 input capture mode the input capture mode is selected when (cpwms = 0), (msnb:msna = 0:0), and (elsnb:elsna 0:0). when a selected edge occurs on the channel input, the current value of the tpm counter is captured into the cnv register, at the same time the chnf bit is set and the channel interrupt is generated if enabled by chnie = 1 (see the following figure). when a channel is configured for input capture, the tpm_chn pin is an edge-sensitive input. elsnb:elsna control bits determine which edge, falling or rising, triggers input- capture event. note that the maximum frequency for the channel input signal to be detected correctly is counter clock divided by 4, which is required to meet nyquist criteria for signal sampling. writes to the cnv register are ignored in input capture mode. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 508 freescale semiconductor, inc.
channel (n) input synchronizer edge detector was falling edge selected? was rising edge selected? rising edge falling edge 0 1 1 0 0 0 cnv d q clk d q clk channel (n) interrupt chnie chnf timer module clock timer module counter figure 30-62. input capture mode the chnf bit is set on the third rising edge of the counter clock after a valid edge occurs on the channel input. 30.4.5 output compare mode the output compare mode is selected when (cpwms = 0), and (msnb:msna = 0:1). in output compare mode, the tpm can generate timed pulses with programmable position, polarity, duration, and frequency. when the counter matches the value in the cnv register of an output compare channel, the channel (n) output can be set, cleared, or toggled. when a channel is initially configured to output compare mode, the channel output updates with its negated value (logic 0 for set/toggle/pulse high and logic one for clear/ pulse low). the chnf bit is set and the channel (n) interrupt is generated (if chnie = 1) at the channel (n) match (tpm counter = cnv). chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 509
tof bit ... ... 0 1 1 1 2 2 3 3 4 45 5 0 0 previous value previous value channel (n) output counter overflow counter overflow counter overflow channel (n) match channel (n) match cnt mod = 0x0005 cnv = 0x0003 chnf bit figure 30-63. example of the output compare mode when the match toggles the channel output tof bit ... ... 0 1 1 1 2 2 3 3 4 45 5 0 0 previous value previous value channel (n) output counter overflow counter overflow counter overflow channel (n) match channel (n) match cnt mod = 0x0005 cnv = 0x0003 chnf bit figure 30-64. example of the output compare mode when the match clears the channel output channel (n) output chnf bit tof bit cnt mod = 0x0005 cnv = 0x0003 counter overflow channel (n) match counter overflow channel (n) match counter overflow ... 0 1 2 3 4 5 0 1 2 3 4 5 0 1 ... previous value previous value figure 30-65. example of the output compare mode when the match sets the channel output it is possible to use the output compare mode with (elsnb:elsna = 0:0). in this case, when the counter reaches the value in the cnv register, the chnf bit is set and the channel (n) interrupt is generated (if chnie = 1), however the channel (n) output is not modified and controlled by tpm. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 510 freescale semiconductor, inc.
30.4.6 edge-aligned pwm (epwm) mode the edge-aligned mode is selected when (cpwms = 0), and (msnb:msna = 1:0). the epwm period is determined by (mod + 0x0001) and the pulse width (duty cycle) is determined by cnv. the chnf bit is set and the channel (n) interrupt is generated (if chnie = 1) at the channel (n) match (tpm counter = cnv), that is, at the end of the pulse width. this type of pwm signal is called edge-aligned because the leading edges of all pwm signals are aligned with the beginning of the period, which is the same for all channels within an tpm. period counter overflow counter overflow counter overflow channel (n) output channel (n) match channel (n) match channel (n) match pulse width figure 30-66. epwm period and pulse width with elsnb:elsna = 1:0 if (elsnb:elsna = 0:0) when the counter reaches the value in the cnv register, the chnf bit is set and the channel (n) interrupt is generated (if chnie = 1), however the channel (n) output is not controlled by tpm. if (elsnb:elsna = 1:0), then the channel (n) output is forced high at the counter overflow (when the zero is loaded into the tpm counter), and it is forced low at the channel (n) match (tpm counter = cnv) (see the following figure). tof bit chnf bit cnt channel (n) output mod = 0x0008 cnv = 0x0005 counter overflow channel (n) match counter overflow ... 0 1 2 3 4 5 6 7 8 0 1 2 ... previous value figure 30-67. epwm signal with elsnb:elsna = 1:0 if (elsnb:elsna = x:1), then the channel (n) output is forced low at the counter overflow (when zero is loaded into the tpm counter), and it is forced high at the channel (n) match (tpm counter = cnv) (see the following figure). chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 511
tof bit chnf bit cnt channel (n) output mod = 0x0008 cnv = 0x0005 counter overflow channel (n) match counter overflow ... 0 1 2 3 4 5 6 7 8 0 1 2 ... previous value figure 30-68. epwm signal with elsnb:elsna = x:1 if (cnv = 0x0000), then the channel (n) output is a 0% duty cycle epwm signal. if (cnv > mod), then the channel (n) output is a 100% duty cycle epwm signal and chnf bit is not set since there is never a channel (n) match. therefore, mod must be less than 0xffff in order to get a 100% duty cycle epwm signal. 30.4.7 center-aligned pwm (cpwm) mode the center-aligned mode is selected when (cpwms = 1) and (msnb:msna = 1:0). the cpwm pulse width (duty cycle) is determined by 2 cnv and the period is determined by 2 mod (see the following figure). mod must be kept in the range of 0x0001 to 0x7fff because values outside this range can produce ambiguous results. in the cpwm mode, the tpm counter counts up until it reaches mod and then counts down until it reaches zero. the chnf bit is set and channel (n) interrupt is generated (if chnie = 1) at the channel (n) match (tpm counter = cnv) when the tpm counting is down (at the begin of the pulse width) and when the tpm counting is up (at the end of the pulse width). this type of pwm signal is called center-aligned because the pulse width centers for all channels are when the tpm counter is zero. the other channel modes are not designed to be used with the up-down counter (cpwms = 1). therefore, all tpm channels should be used in cpwm mode when (cpwms = 1). functional description kl04 sub-family reference manual, rev. 3.1, november 2012 512 freescale semiconductor, inc.
pulse width counter overflow timer module counter = mod period (2 x cnv) (2 x mod) timer module counter = 0 channel (n) match (timer module counting is down) channel (n) match (timer module counting is up) counter overflow timer module counter = mod channel (n) output figure 30-69. cpwm period and pulse width with elsnb:elsna = 1:0 if (elsnb:elsna = 0:0) when the tpm counter reaches the value in the cnv register, the chnf bit is set and the channel (n) interrupt is generated (if chnie = 1), however the channel (n) output is not controlled by tpm. if (elsnb:elsna = 1:0), then the channel (n) output is forced high at the channel (n) match (tpm counter = cnv) when counting down, and it is forced low at the channel (n) match when counting up (see the following figure). tof bit ... 7 8 8 7 7 7 6 6 6 5 5 5 4 43 3 2 21 0 1 ... previous value cnt channel (n) output counter overflow channel (n) match in down counting channel (n) match in up counting channel (n) match in down counting counter overflow chnf bit mod = 0x0008 cnv = 0x0005 figure 30-70. cpwm signal with elsnb:elsna = 1:0 if (elsnb:elsna = x:1), then the channel (n) output is forced low at the channel (n) match (tpm counter = cnv) when counting down, and it is forced high at the channel (n) match when counting up (see the following figure). tof bit ... 7 8 8 7 7 7 6 6 6 5 5 5 4 43 3 2 21 0 1 ... previous value cnt channel (n) output counter overflow channel (n) match in down counting channel (n) match in up counting channel (n) match in down counting counter overflow chnf bit mod = 0x0008 cnv = 0x0005 figure 30-71. cpwm signal with elsnb:elsna = x:1 chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 513
if (cnv = 0x0000) then the channel (n) output is a 0% duty cycle cpwm signal. if (cnv > mod), then the channel (n) output is a 100% duty cycle cpwm signal, although the chnf bit is set when the counter changes from incrementing to decrementing. therefore, mod must be less than 0xffff in order to get a 100% duty cycle cpwm signal. 30.4.8 registers updated from write buffers 30.4.8.1 mod register update if (cmod[1:0] = 0:0) then mod register is updated when mod register is written. if (cmod[1:0] 0:0), then mod register is updated according to the cpwms bit, that is: ? if the selected mode is not cpwm then mod register is updated after mod register was written and the tpm counter changes from mod to zero. ? if the selected mode is cpwm then mod register is updated after mod register was written and the tpm counter changes from mod to (mod C 1). 30.4.8.2 cnv register update if (cmod[1:0] = 0:0) then cnv register is updated when cnv register is written. if (cmod[1:0] 0:0), then cnv register is updated according to the selected mode, that is: ? if the selected mode is output compare then cnv register is updated on the next tpm counter increment (end of the prescaler counting) after cnv register was written. ? if the selected mode is epwm then cnv register is updated after cnv register was written and the tpm counter changes from mod to zero. ? if the selected mode is cpwm then cnv register is updated after cnv register was written and the tpm counter changes from mod to (mod C 1). functional description kl04 sub-family reference manual, rev. 3.1, november 2012 514 freescale semiconductor, inc.
30.4.9 dma the channel generates a dma transfer request according to dma and chnie bits (see the following table). table 30-83. channel dma transfer request dma chnie channel dma transfer request channel interrupt 0 0 the channel dma transfer request is not generated. the channel interrupt is not generated. 0 1 the channel dma transfer request is not generated. the channel interrupt is generated if (chnf = 1). 1 0 the channel dma transfer request is generated if (chnf = 1). the channel interrupt is not generated. 1 1 the channel dma transfer request is generated if (chnf = 1). the channel interrupt is generated if (chnf = 1). if dma = 1, the chnf bit can be cleared either by channel dma transfer done or writing a one to chnf bit (see the following table). table 30-84. clear chnf bit dma how chnf bit can be cleared 0 chnf bit is cleared by writing a 1 to chnf bit. 1 chnf bit is cleared either when the channel dma transfer is done or by writing a 1 to chnf bit. 30.4.10 reset overview the tpm is reset whenever any chip reset occurs. when the tpm exits from reset: ? the tpm counter and the prescaler counter are zero and are stopped (cmod[1:0] = 0:0); ? the timer overflow interrupt is zero; ? the channels interrupts are zero; ? the channels are in input capture mode; ? the channels outputs are zero; ? the channels pins are not controlled by tpm (els(n)b:els(n)a = 0:0). 30.4.11 tpm interrupts this section describes tpm interrupts. chapter 30 timer/pwm module (tpm) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 515
30.4.11.1 timer overflow interrupt the timer overflow interrupt is generated when (toie = 1) and (tof = 1). 30.4.11.2 channel (n) interrupt the channel (n) interrupt is generated when (chnie = 1) and (chnf = 1). functional description kl04 sub-family reference manual, rev. 3.1, november 2012 516 freescale semiconductor, inc.
chapter 31 periodic interrupt timer (pit-rti) 31.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the pit module is an array of timers that can be used to raise interrupts and trigger dma channels. 31.1.1 block diagram the following figure shows the block diagram of the pit-rti module. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 517
timer n timer 1 pit peripheral load_value pit triggers bus clock bus peripheral iinterrupts registers figure 31-1. block diagram of the pit note see the chip configuration details for the number of pit channels used in this mcu. 31.1.2 features the main features of this block are: ? ability of timers to generate dma trigger pulses ? ability of timers to generate interrupts ? maskable interrupts ? independent timeout periods for each timer 31.2 signal description the pit module has no external pins. signal description kl04 sub-family reference manual, rev. 3.1, november 2012 518 freescale semiconductor, inc.
31.3 memory map/register description this section provides a detailed description of all registers accessible in the pit module. note ? reserved registers will read as 0, writes will have no effect. ? see the chip configuration details for the number of pit channels used in this mcu. table 31-2. timer channel n address offset use access channel + 0x00 timer load value register r/w channel + 0x04 current timer value register r channel + 0x08 timer control register r/w channel + 0x0c timer flag register r/w pit memory map absolute address (hex) register name width (in bits) access reset value section/ page 4003_7000 pit module control register (pit_mcr) 32 r/w 0000_0002h 31.3.1/519 4003_70e0 pit upper lifetime timer register (pit_ltmr64h) 32 r 0000_0000h 31.3.2/521 4003_70e4 pit lower lifetime timer register (pit_ltmr64l) 32 r 0000_0000h 31.3.3/521 4003_7100 timer load value register (pit_ldval0) 32 r/w 0000_0000h 31.3.4/522 4003_7104 current timer value register (pit_cval0) 32 r 0000_0000h 31.3.5/522 4003_7108 timer control register (pit_tctrl0) 32 r/w 0000_0000h 31.3.6/523 4003_710c timer flag register (pit_tflg0) 32 r/w 0000_0000h 31.3.7/524 4003_7110 timer load value register (pit_ldval1) 32 r/w 0000_0000h 31.3.4/522 4003_7114 current timer value register (pit_cval1) 32 r 0000_0000h 31.3.5/522 4003_7118 timer control register (pit_tctrl1) 32 r/w 0000_0000h 31.3.6/523 4003_711c timer flag register (pit_tflg1) 32 r/w 0000_0000h 31.3.7/524 31.3.1 pit module control register (pit_mcr) this register enables or disables the pit timer clocks and controls the timers when the pit enters the debug mode. chapter 31 periodic interrupt timer (pit-rti) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 519
address: 4003_7000h base + 0h offset = 4003_7000h bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 r 0 reserved mdis frz w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 pit_mcr field descriptions field description 0C28 reserved this field is reserved. this read-only field is reserved and always has the value 0. 29 reserved this field is reserved. 30 mdis module disable - (pit section) disables the standard timers. this field must be enabled before any other setup is done. 0 clock for standard pit timers is enabled. 1 clock for standard pit timers is disabled. 31 frz freeze allows the timers to be stopped when the device enters the debug mode. 0 timers continue to run in debug mode. 1 timers are stopped in debug mode. memory map/register description kl04 sub-family reference manual, rev. 3.1, november 2012 520 freescale semiconductor, inc.
31.3.2 pit upper lifetime timer register (pit_ltmr64h) this register is intended for applications that chain timer 0 and timer 1 to build a 64-bit lifetimer. address: 4003_7000h base + e0h offset = 4003_70e0h bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 r lth w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pit_ltmr64h field descriptions field description 0C31 lth life timer value shows the timer value of timer 1. if this register is read at a time t1, ltmr64l shows the value of timer 0 at time t1. 31.3.3 pit lower lifetime timer register (pit_ltmr64l) this register is intended for applications that chain timer 0 and timer 1 to build a 64-bit lifetimer. to use ltmr64h and ltmr64l, timer 0 and timer 1 need to be chained. to obtain the correct value, first read ltmr64h and then ltmr64l. ltmr64h will have the value of cval1 at the time of the first access, ltmr64l will have the value of cval0 at the time of the first access, therefore the application does not need to worry about carry-over effects of the running counter. address: 4003_7000h base + e4h offset = 4003_70e4h bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 r ltl w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pit_ltmr64l field descriptions field description 0C31 ltl life timer value shows the value of timer 0 at the time ltmr64h was last read. it will only update if ltmr64h is read. chapter 31 periodic interrupt timer (pit-rti) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 521
31.3.4 timer load value register (pit_ldval n ) these registers select the timeout period for the timer interrupts. address: 4003_7000h base + 100h offset + (16d i), where i=0d to 1d bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 r tsv w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pit_ldval n field descriptions field description 0C31 tsv timer start value sets the timer start value. the timer will count down until it reaches 0, then it will generate an interrupt and load this register value again. writing a new value to this register will not restart the timer; instead the value will be loaded after the timer expires. to abort the current cycle and start a timer period with the new value, the timer must be disabled and enabled again. 31.3.5 current timer value register (pit_cval n ) these registers indicate the current timer position. address: 4003_7000h base + 104h offset + (16d i), where i=0d to 1d bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 r tvl w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pit_cval n field descriptions field description 0C31 tvl current timer value represents the current timer value, if the timer is enabled. note: ? if the timer is disabled, do not use this field as its value is unreliable. ? the timer uses a downcounter. the timer values are frozen in debug mode if mcr[frz] is set. memory map/register description kl04 sub-family reference manual, rev. 3.1, november 2012 522 freescale semiconductor, inc.
31.3.6 timer control register (pit_tctrl n ) these register contain the control bits for each timer. address: 4003_7000h base + 108h offset + (16d i), where i=0d to 1d bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 r 0 chn tie ten w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pit_tctrl n field descriptions field description 0C28 reserved this field is reserved. this read-only field is reserved and always has the value 0. 29 chn chain mode when activated, timer n-1 needs to expire before timer n can decrement by 1. timer 0 can not be changed. 0 timer is not chained. 1 timer is chained to previous timer. for example, for channel 2, if this field is set, timer 2 is chained to timer 1. 30 tie timer interrupt enable when an interrupt is pending, or, tflgn[tif] is set, enabling the interrupt will immediately cause an interrupt event. to avoid this, the associated tflgn[tif] must be cleared first. 0 interrupt requests from timer n are disabled. 1 interrupt will be requested whenever tif is set. 31 ten timer enable enables or disables the timer. 0 timer n is disabled. 1 timer n is enabled. chapter 31 periodic interrupt timer (pit-rti) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 523
31.3.7 timer flag register (pit_tflg n ) these registers hold the pit interrupt flags. address: 4003_7000h base + 10ch offset + (16d i), where i=0d to 1d bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 r 0 tif w w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pit_tflg n field descriptions field description 0C30 reserved this field is reserved. this read-only field is reserved and always has the value 0. 31 tif timer interrupt flag sets to 1 at the end of the timer period. writing 1 to this flag clears it. writing 0 has no effect. if enabled, or, when tctrln[tie] = 1, tif causes an interrupt request. 0 timeout has not yet occurred. 1 timeout has occurred. 31.4 functional description this section provides the functional description of the module. 31.4.1 general operation this section gives detailed information on the internal operation of the module. each timer can be used to generate trigger pulses and interrupts. each interrupt is available on a separate interrupt line. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 524 freescale semiconductor, inc.
31.4.1.1 timers the timers generate triggers at periodic intervals, when enabled. the timers load the start values as specified in their ldval registers, count down to 0 and then load the respective start value again. each time a timer reaches 0, it will generate a trigger pulse and set the interrupt flag. all interrupts can be enabled or masked by setting tctrln[tie]. a new interrupt can be generated only after the previous one is cleared. if desired, the current counter value of the timer can be read via the cval registers. the counter period can be restarted, by first disabling, and then enabling the timer with tctrln[ten]. see the following figure. p1 timer enabled disable timer p1 p1 start value = p1 trigger event p1 re-enable timer figure 31-17. stopping and starting a timer the counter period of a running timer can be modified, by first disabling the timer, setting a new load value, and then enabling the timer again. see the following figure. timer enabled disable timer, p1 p1 re-enable timer start value = p1 trigger event set new load value p2 p2 p2 figure 31-18. modifying running timer period it is also possible to change the counter period without restarting the timer by writing ldval with the new load value. this value will then be loaded after the next trigger event. see the following figure. chapter 31 periodic interrupt timer (pit-rti) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 525
timer enabled p1 p1 start value = p1 trigger event p2 p2 p1 new start value p2 set figure 31-19. dynamically setting a new load value 31.4.1.2 debug mode in debug mode, the timers will be frozen based on mcr[frz]. this is intended to aid software development, allowing the developer to halt the processor, investigate the current state of the system, for example, the timer values, and then continue the operation. 31.4.2 interrupts all the timers support interrupt generation. see the mcu specification for related vector addresses and priorities. timer interrupts can be enabled by setting tctrln[tie]. tflgn[tif] are set to 1 when a timeout occurs on the associated timer, and are cleared to 0 by writing a 1 to the corresponding tflgn[tif]. 31.4.3 chained timers when a timer has chain mode enabled, it will only count after the previous timer has expired. so if timer n-1 has counted down to 0, counter n will decrement the value by one. this allows to chain some of the timers together to form a longer timer. the first timer (timer 0) cannot be chained to any other timer. 31.5 initialization and application information in the example configuration: ? the pit clock has a frequency of 50 mhz. initialization and application information kl04 sub-family reference manual, rev. 3.1, november 2012 526 freescale semiconductor, inc.
? timer 1 creates an interrupt every 5.12 ms. ? timer 3 creates a trigger event every 30 ms. the pit module must be activated by writing a 0 to mcr[mdis]. the 50 mhz clock frequency equates to a clock period of 20 ns. timer 1 needs to trigger every 5.12 ms/20 ns = 256,000 cycles and timer 3 every 30 ms/20 ns = 1,500,000 cycles. the value for the ldval register trigger is calculated as: ldval trigger = (period / clock period) -1 this means ldval1 and ldval3 must be written with 0x0003e7ff and 0x0016e35f respectively. the interrupt for timer 1 is enabled by setting tctrl1[tie]. the timer is started by writing 1 to tctrl1[ten]. timer 3 shall be used only for triggering. therefore, timer 3 is started by writing a 1 to tctrl3[ten]. tctrl3[tie] stays at 0. the following example code matches the described setup: // turn on pit pit_mcr = 0x00; // timer 1 pit_ldval1 = 0x0003e7ff; // setup timer 1 for 256000 cycles pit_tctrl1 = tie; // enable timer 1 interrupts pit_tctrl1 |= ten; // start timer 1 // timer 3 pit_ldval3 = 0x0016e35f; // setup timer 3for 1500000 cycles pit_tctrl3 |= ten; // start timer 3 31.6 example configuration for chained timers in the example configuration: ? the pit clock has a frequency of 100 mhz. ? timers 1 and 2 are available. ? an interrupt shall be raised every 1 hour. the pit module needs to be activated by writing a 0 to mcr[mdis]. chapter 31 periodic interrupt timer (pit-rti) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 527
the 100 mhz clock frequency equates to a clock period of 10 ns, so the pit needs to count for 6000 million cycles, which is more than a single timer can do. so, timer 1 is set up to trigger every 6 s (600 million cycles). timer 2 is chained to timer 1 and programmed to trigger 10 times. the value for the ldval register trigger is calculated as number of cycles-1, so ldval1 receives the value 0x23c345ff and ldval2 receives the value 0x00000009. the interrupt for timer 2 is enabled by setting tctrl2[tie], the chain mode is activated by setting tctrl2[chn], and the timer is started by writing a 1 to tctrl2[ten]. tctrl1[ten] needs to be set, and tctrl1[chn] and tctrl1[tie] are cleared. the following example code matches the described setup: // turn on pit pit_mcr = 0x00; // timer 2 pit_ldval2 = 0x00000009; // setup timer 2 for 10 counts pit_tctrl2 = tie; // enable timer 2 interrupt pit_tctrl2 |= chn; // chain timer 2 to timer 1 pit_tctrl2 |= ten; // start timer 2 // timer 1 pit_ldval1 = 0x23c345ff; // setup timer 1 for 600 000 000 cycles pit_tctrl1 = ten; // start timer 1 31.7 example configuration for the lifetime timer to configure the lifetimer timer, channels 0 and 1 need to be chained together. first the pit module needs to be activated by writing a 0 to the mdis bit in the ctrl register, then the ldval registers need to be set to the maximum value. the timer is a downcounter. the following example code matches the described setup: // turn on pit pit_mcr = 0x00; // timer 1 pit_ldval1 = 0xffffffff; // setup timer 1 for maximum counting period pit_tctrl1 = 0x0; // disable timer 1 interrupts pit_tctrl1 |= chn; // chain timer 1 to timer 0 pit_tctrl1 |= ten; // start timer 1 // timer 0 example configuration for the lifetime timer kl04 sub-family reference manual, rev. 3.1, november 2012 528 freescale semiconductor, inc.
pit_ldval0 = 0xffffffff; // setup timer 0 for maximum counting period pit_tctrl0 = ten; // start timer 0 to access the lifetime, read first ltmr64h and then ltmr64l. current_uptime = pit_ltmr64h<<32; current_uptime = current_uptime + pit_ltmr64l; chapter 31 periodic interrupt timer (pit-rti) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 529
example configuration for the lifetime timer kl04 sub-family reference manual, rev. 3.1, november 2012 530 freescale semiconductor, inc.
chapter 32 low-power timer (lptmr) 32.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the low-power timer (lptmr) can be configured to operate as a time counter with optional prescaler, or as a pulse counter with optional glitch filter, across all power modes, including the low-leakage modes. it can also continue operating through most system reset events, allowing it to be used as a time of day counter. 32.1.1 features the features of the lptmr module include: ? 16-bit time counter or pulse counter with compare ? optional interrupt can generate asynchronous wakeup from any low-power mode ? hardware trigger output ? counter supports free-running mode or reset on compare ? configurable clock source for prescaler/glitch filter ? configurable input source for pulse counter ? rising-edge or falling-edge 32.1.2 modes of operation the following table describes the operation of the lptmr module in various modes. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 531
table 32-1. modes of operation modes description run the lptmr operates normally. wait the lptmr continues to operate normally and may be configured to exit the low-power mode by generating an interrupt request. stop the lptmr continues to operate normally and may be configured to exit the low-power mode by generating an interrupt request. low-leakage the lptmr continues to operate normally and may be configured to exit the low-power mode by generating an interrupt request. debug the lptmr operates normally in pulse counter mode, but counter does not increment in time counter mode. 32.2 lptmr signal descriptions table 32-2. lptmr signal descriptions signal i/o description lptmr_alt n i pulse counter input pin 32.2.1 detailed signal descriptions table 32-3. lptmr interfacedetailed signal descriptions signal i/o description lptmr_alt n i pulse counter input the lptmr can select one of the input pins to be used in pulse counter mode. state meaning assertionif configured for pulse counter mode with active-high input, then assertion causes the cnr to increment. deassertionif configured for pulse counter mode with active-low input, then deassertion causes the cnr to increment. timing assertion or deassertion may occur at any time; input may assert asynchronously to the bus clock. 32.3 memory map and register definition lptmr signal descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 532 freescale semiconductor, inc.
lptmr memory map absolute address (hex) register name width (in bits) access reset value section/ page 4004_0000 low power timer control status register (lptmr0_csr) 32 r/w 0000_0000h 32.3.1/533 4004_0004 low power timer prescale register (lptmr0_psr) 32 r/w 0000_0000h 32.3.2/534 4004_0008 low power timer compare register (lptmr0_cmr) 32 r/w 0000_0000h 32.3.3/536 4004_000c low power timer counter register (lptmr0_cnr) 32 r 0000_0000h 32.3.4/536 32.3.1 low power timer control status register (lptmr x _csr) address: 4004_0000h base + 0h offset = 4004_0000h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 tcf tie tps tpp tfc tms ten w w1c reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 lptmr x _csr field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 tcf timer compare flag tcf is set when the lptmr is enabled and the cnr equals the cmr and increments. tcf is cleared when the lptmr is disabled or a logic 1 is written to it. 0 the value of cnr is not equal to cmr and increments. 1 the value of cnr is equal to cmr and increments. 6 tie timer interrupt enable when tie is set, the lptmr interrupt is generated whenever tcf is also set. 0 timer interrupt disabled. 1 timer interrupt enabled. 5C4 tps timer pin select configures the input source to be used in pulse counter mode. tps must be altered only when the lptmr is disabled. the input connections vary by device. see the chip configuration details for information on the connections to these inputs. 00 pulse counter input 0 is selected. table continues on the next page... chapter 32 low-power timer (lptmr) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 533
lptmr x _csr field descriptions (continued) field description 01 pulse counter input 1 is selected. 10 pulse counter input 2 is selected. 11 pulse counter input 3 is selected. 3 tpp timer pin polarity configures the polarity of the input source in pulse counter mode. tpp must be changed only when the lptmr is disabled. 0 pulse counter input source is active-high, and the cnr will increment on the rising-edge. 1 pulse counter input source is active-low, and the cnr will increment on the falling-edge. 2 tfc timer free-running counter when clear, tfc configures the cnr to reset whenever tcf is set. when set, tfc configures the cnr to reset on overflow. tfc must be altered only when the lptmr is disabled. 0 cnr is reset whenever tcf is set. 1 cnr is reset on overflow. 1 tms timer mode select configures the mode of the lptmr. tms must be altered only when the lptmr is disabled. 0 time counter mode. 1 pulse counter mode. 0 ten timer enable when ten is clear, it resets the lptmr internal logic, including the cnr and tcf. when ten is set, the lptmr is enabled. while writing 1 to this field, csr[5:1] must not be altered. 0 lptmr is disabled and internal logic is reset. 1 lptmr is enabled. 32.3.2 low power timer prescale register (lptmr x _psr) address: 4004_0000h base + 4h offset = 4004_0004h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 prescale pbyp pcs w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 534 freescale semiconductor, inc.
lptmr x _psr field descriptions field description 31C7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6C3 prescale prescale value configures the size of the prescaler in time counter mode or width of the glitch filter in pulse counter mode. prescale must be altered only when the lptmr is disabled. 0000 prescaler divides the prescaler clock by 2; glitch filter does not support this configuration. 0001 prescaler divides the prescaler clock by 4; glitch filter recognizes change on input pin after 2 rising clock edges. 0010 prescaler divides the prescaler clock by 8; glitch filter recognizes change on input pin after 4 rising clock edges. 0011 prescaler divides the prescaler clock by 16; glitch filter recognizes change on input pin after 8 rising clock edges. 0100 prescaler divides the prescaler clock by 32; glitch filter recognizes change on input pin after 16 rising clock edges. 0101 prescaler divides the prescaler clock by 64; glitch filter recognizes change on input pin after 32 rising clock edges. 0110 prescaler divides the prescaler clock by 128; glitch filter recognizes change on input pin after 64 rising clock edges. 0111 prescaler divides the prescaler clock by 256; glitch filter recognizes change on input pin after 128 rising clock edges. 1000 prescaler divides the prescaler clock by 512; glitch filter recognizes change on input pin after 256 rising clock edges. 1001 prescaler divides the prescaler clock by 1024; glitch filter recognizes change on input pin after 512 rising clock edges. 1010 prescaler divides the prescaler clock by 2048; glitch filter recognizes change on input pin after 1024 rising clock edges. 1011 prescaler divides the prescaler clock by 4096; glitch filter recognizes change on input pin after 2048 rising clock edges. 1100 prescaler divides the prescaler clock by 8192; glitch filter recognizes change on input pin after 4096 rising clock edges. 1101 prescaler divides the prescaler clock by 16,384; glitch filter recognizes change on input pin after 8192 rising clock edges. 1110 prescaler divides the prescaler clock by 32,768; glitch filter recognizes change on input pin after 16,384 rising clock edges. 1111 prescaler divides the prescaler clock by 65,536; glitch filter recognizes change on input pin after 32,768 rising clock edges. 2 pbyp prescaler bypass when pbyp is set, the selected prescaler clock in time counter mode or selected input source in pulse counter mode directly clocks the cnr. when pbyp is clear, the cnr is clocked by the output of the prescaler/glitch filter. pbyp must be altered only when the lptmr is disabled. 0 prescaler/glitch filter is enabled. 1 prescaler/glitch filter is bypassed. 1C0 pcs prescaler clock select selects the clock to be used by the lptmr prescaler/glitch filter. pcs must be altered only when the lptmr is disabled. the clock connections vary by device. note: see the chip configuration details for information on the connections to these inputs. table continues on the next page... chapter 32 low-power timer (lptmr) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 535
lptmr x _psr field descriptions (continued) field description 00 prescaler/glitch filter clock 0 selected. 01 prescaler/glitch filter clock 1 selected. 10 prescaler/glitch filter clock 2 selected. 11 prescaler/glitch filter clock 3 selected. 32.3.3 low power timer compare register (lptmr x _cmr) address: 4004_0000h base + 8h offset = 4004_0008h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 compare w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 lptmr x _cmr field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 compare compare value when the lptmr is enabled and the cnr equals the value in the cmr and increments, tcf is set and the hardware trigger asserts until the next time the cnr increments. if the cmr is 0, the hardware trigger will remain asserted until the lptmr is disabled. if the lptmr is enabled, the cmr must be altered only when tcf is set. 32.3.4 low power timer counter register (lptmr x _cnr) address: 4004_0000h base + ch offset = 4004_000ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 counter w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 lptmr x _cnr field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 counter counter value memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 536 freescale semiconductor, inc.
32.4 functional description 32.4.1 lptmr power and reset the lptmr remains powered in all power modes, including low-leakage modes. if the lptmr is not required to remain operating during a low-power mode, then it must be disabled before entering the mode. the lptmr is reset only on global power on reset (por) or low voltage detect (lvd). when configuring the lptmr registers, the csr must be initially written with the timer disabled, before configuring the psr and cmr. then, csr[tie] must be set as the last step in the initialization. this ensures the lptmr is configured correctly and the lptmr counter is reset to zero following a warm reset. 32.4.2 lptmr clocking the lptmr prescaler/glitch filter can be clocked by one of the four clocks. the clock source must be enabled before the lptmr is enabled. note the clock source selected may need to be configured to remain enabled in low-power modes, otherwise the lptmr will not operate during low-power modes. in pulse counter mode with the prescaler/glitch filter bypassed, the selected input source directly clocks the cnr and no other clock source is required. to minimize power in this case, configure the prescaler clock source for a clock that is not toggling. note the clock source or pulse input source selected for the lptmr should not exceed the frequency f lptmr defined in the device datasheet. 32.4.3 lptmr prescaler/glitch filter the lptmr prescaler and glitch filter share the same logic which operates as a prescaler in time counter mode and as a glitch filter in pulse counter mode. chapter 32 low-power timer (lptmr) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 537
note the prescaler/glitch filter configuration must not be altered when the lptmr is enabled. 32.4.3.1 prescaler enabled in time counter mode, when the prescaler is enabled, the output of the prescaler directly clocks the cnr. when the lptmr is enabled, the cnr will increment every 2 2 to 2 16 prescaler clock cycles. after the lptmr is enabled, the first increment of the cnr will take an additional one or two prescaler clock cycles due to synchronization logic. 32.4.3.2 prescaler bypassed in time counter mode, when the prescaler is bypassed, the selected prescaler clock increments the cnr on every clock cycle. when the lptmr is enabled, the first increment will take an additional one or two prescaler clock cycles due to synchronization logic. 32.4.3.3 glitch filter in pulse counter mode, when the glitch filter is enabled, the output of the glitch filter directly clocks the cnr. when the lptmr is first enabled, the output of the glitch filter is asserted, that is, logic 1 for active-high and logic 0 for active-low. the following table shows the change in glitch filter output with the selected input source. if then the selected input source remains deasserted for at least 2 1 to 2 15 consecutive prescaler clock rising edges the glitch filter output will also deassert. the selected input source remains asserted for at least 2 1 to 2 15 consecutive prescaler clock rising-edges the glitch filter output will also assert. note the input is only sampled on the rising clock edge. the cnr will increment each time the glitch filter output asserts. in pulse counter mode, the maximum rate at which the cnr can increment is once every 2 2 to 2 16 prescaler clock edges. when first enabled, the glitch filter will wait an additional one or two prescaler clock edges due to synchronization logic. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 538 freescale semiconductor, inc.
32.4.3.4 glitch filter bypassed in pulse counter mode, when the glitch filter is bypassed, the selected input source increments the cnr every time it asserts. before the lptmr is first enabled, the selected input source is forced to be asserted. this prevents the cnr from incrementing if the selected input source is already asserted when the lptmr is first enabled. 32.4.4 lptmr compare when the cnr equals the value of the cmr and increments, the following events occur: ? csr[tcf] is set. ? lptmr interrupt is generated if csr[tie] is also set. ? lptmr hardware trigger is generated. ? cnr is reset if csr[tfc] is clear. when the lptmr is enabled, the cmr can be altered only when csr[tcf] is set. when updating the cmr, the cmr must be written and csr[tcf] must be cleared before the lptmr counter has incremented past the new lptmr compare value. 32.4.5 lptmr counter the cnr increments by one on every: ? prescaler clock in time counter mode with prescaler bypassed ? prescaler output in time counter mode with prescaler enabled ? input source assertion in pulse counter mode with glitch filter bypassed ? glitch filter output in pulse counter mode with glitch filter enabled the cnr is reset when the lptmr is disabled or if the counter register overflows. if csr[tfc] is cleared, then the cnr is also reset whenever csr[tcf] is set. the cnr continues incrementing when the core is halted in debug mode when configured for pulse counter mode, the cnr will stop incrementing when the core is halted in debug mode when configured for time counter mode. the cnr cannot be initialized, but can be read at any time. on each read of the cnr, software must first write to the cnr with any value. this will synchronize and register the current value of the cnr into a temporary register. the contents of the temporary register are returned on each read of the cnr. when reading the cnr, the bus clock must be at least two times faster than the rate at which the lptmr counter is incrementing, otherwise incorrect data may be returned. chapter 32 low-power timer (lptmr) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 539
32.4.6 lptmr hardware trigger the lptmr hardware trigger asserts at the same time the csr[tcf] is set and can be used to trigger hardware events in other peripherals without software intervention. the hardware trigger is always enabled. when then the cmr is set to 0 with csr[tfc] clear the lptmr hardware trigger will assert on the first compare and does not deassert. the cmr is set to a nonzero value, or, if csr[tfc] is set the lptmr hardware trigger will assert on each compare and deassert on the following increment of the cnr. 32.4.7 lptmr interrupt the lptmr interrupt is generated whenever csr[tie] and csr[tcf] are set. csr[tcf] is cleared by disabling the lptmr or by writing a logic 1 to it. csr[tie] can be altered and csr[tcf] can be cleared while the lptmr is enabled. the lptmr interrupt is generated asynchronously to the system clock and can be used to generate a wakeup from any low-power mode, including the low-leakage modes, provided the lptmr is enabled as a wakeup source. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 540 freescale semiconductor, inc.
chapter 33 real time clock (rtc) 33.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. 33.1.1 features the rtc module features include: ? 32-bit seconds counter with roll-over protection and 32-bit alarm ? 16-bit prescaler with compensation that can correct errors between 0.12 ppm and 3906 ppm ? register write protection ? lock register requires por or software reset to enable write access ? 1 hz square wave output 33.1.2 modes of operation the rtc remains functional in all low power modes and can generate an interrupt to exit any low power mode. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 541
33.1.3 rtc signal descriptions table 33-1. rtc signal descriptions signal description i/o rtc_clkout 1 hz square-wave output o 33.1.3.1 rtc clock output the clock to the seconds counter is available on the rtc_clkout signal. it is a 1 hz square wave output. 33.2 register definition all registers must be accessed using 32-bit writes and all register accesses incur three wait states. write accesses to any register by non-supervisor mode software, when the supervisor access bit in the control register is clear, will terminate with a bus error. read accesses by non-supervisor mode software complete as normal. writing to a register protected by the lock register does not generate a bus error, but the write will not complete. rtc memory map absolute address (hex) register name width (in bits) access reset value section/ page 4003_d000 rtc time seconds register (rtc_tsr) 32 r/w 0000_0000h 33.2.1/543 4003_d004 rtc time prescaler register (rtc_tpr) 32 r/w 0000_0000h 33.2.2/543 4003_d008 rtc time alarm register (rtc_tar) 32 r/w 0000_0000h 33.2.3/544 4003_d00c rtc time compensation register (rtc_tcr) 32 r/w 0000_0000h 33.2.4/544 4003_d010 rtc control register (rtc_cr) 32 r/w 0000_0000h 33.2.5/545 4003_d014 rtc status register (rtc_sr) 32 r/w 0000_0001h 33.2.6/547 4003_d018 rtc lock register (rtc_lr) 32 r/w 0000_00ffh 33.2.7/548 4003_d01c rtc interrupt enable register (rtc_ier) 32 r/w 0000_0007h 33.2.8/549 register definition kl04 sub-family reference manual, rev. 3.1, november 2012 542 freescale semiconductor, inc.
33.2.1 rtc time seconds register (rtc_tsr) address: 4003_d000h base + 0h offset = 4003_d000h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r tsr w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 rtc_tsr field descriptions field description 31C0 tsr time seconds register when the time counter is enabled, the tsr is read only and increments once a second provided sr[tof] or sr[tif] are not set. the time counter will read as zero when sr[tof] or sr[tif] are set. when the time counter is disabled, the tsr can be read or written. writing to the tsr when the time counter is disabled will clear the sr[tof] and/or the sr[tif]. writing to tsr with zero is supported, but not recommended because tsr will read as zero when sr[tif] or sr[tof] are set (indicating the time is invalid). 33.2.2 rtc time prescaler register (rtc_tpr) address: 4003_d000h base + 4h offset = 4003_d004h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 tpr w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 rtc_tpr field descriptions field description 31C16 reserved this field is reserved. this read-only field is reserved and always has the value 0. 15C0 tpr time prescaler register when the time counter is enabled, the tpr is read only and increments every 32.768 khz clock cycle. the time counter will read as zero when sr[tof] or sr[tif] are set. when the time counter is disabled, the tpr can be read or written. the tsr[tsr] increments when bit 14 of the tpr transitions from a logic one to a logic zero. chapter 33 real time clock (rtc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 543
33.2.3 rtc time alarm register (rtc_tar) address: 4003_d000h base + 8h offset = 4003_d008h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r tar w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 rtc_tar field descriptions field description 31C0 tar time alarm register when the time counter is enabled, the sr[taf] is set whenever the tar[tar] equals the tsr[tsr] and the tsr[tsr] increments. writing to the tar clears the sr[taf]. 33.2.4 rtc time compensation register (rtc_tcr) address: 4003_d000h base + ch offset = 4003_d00ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r cic tcv cir tcr w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 rtc_tcr field descriptions field description 31C24 cic compensation interval counter current value of the compensation interval counter. if the compensation interval counter equals zero then it is loaded with the contents of the cir. if the cic does not equal zero then it is decremented once a second. 23C16 tcv time compensation value current value used by the compensation logic for the present second interval. updated once a second if the cic equals 0 with the contents of the tcr field. if the cic does not equal zero then it is loaded with zero (compensation is not enabled for that second increment). 15C8 cir compensation interval register configures the compensation interval in seconds from 1 to 256 to control how frequently the tcr should adjust the number of 32.768 khz cycles in each second. the value written should be one less than the number of seconds. for example, write zero to configure for a compensation interval of one second. this register is double buffered and writes do not take affect until the end of the current compensation interval. 7C0 tcr time compensation register configures the number of 32.768 khz clock cycles in each second. this register is double buffered and writes do not take affect until the end of the current compensation interval. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 544 freescale semiconductor, inc.
rtc_tcr field descriptions (continued) field description 80h time prescaler register overflows every 32896 clock cycles. ... ... ffh time prescaler register overflows every 32769 clock cycles. 00h time prescaler register overflows every 32768 clock cycles. 01h time prescaler register overflows every 32767 clock cycles. ... ... 7fh time prescaler register overflows every 32641 clock cycles. 33.2.5 rtc control register (rtc_cr) address: 4003_d000h base + 10h offset = 4003_d010h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 reserved sc2p sc4p sc8p sc16p clko osce 0 um sup wpe swr w 0 reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 rtc_cr field descriptions field description 31C15 reserved this field is reserved. this read-only field is reserved and always has the value 0. table continues on the next page... chapter 33 real time clock (rtc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 545
rtc_cr field descriptions (continued) field description 14 reserved this field is reserved. it must always be written to 0. 13 sc2p oscillator 2pf load configure 0 disable the load. 1 enable the additional load. 12 sc4p oscillator 4pf load configure 0 disable the load. 1 enable the additional load. 11 sc8p oscillator 8pf load configure 0 disable the load. 1 enable the additional load. 10 sc16p oscillator 16pf load configure 0 disable the load. 1 enable the additional load. 9 clko clock output 0 the 32 khz clock is output to other peripherals. 1 the 32 khz clock is not output to other peripherals. 8 osce oscillator enable 0 32.768 khz oscillator is disabled. 1 32.768 khz oscillator is enabled. after setting this bit, wait the oscillator startup time before enabling the time counter to allow the 32.768 khz clock time to stabilize. 7C4 reserved this field is reserved. this read-only field is reserved and always has the value 0. 3 um update mode allows sr[tce] to be written even when the status register is locked. when set, the sr[tce] can always be written if the sr[tif] or sr[tof] are set or if the sr[tce] is clear. 0 registers cannot be written when locked. 1 registers can be written when locked under limited conditions. 2 sup supervisor access 0 non-supervisor mode write accesses are not supported and generate a bus error. 1 non-supervisor mode write accesses are supported. 1 wpe wakeup pin enable the wakeup pin is optional and not available on all devices. 0 wakeup pin is disabled. 1 wakeup pin is enabled and wakeup pin asserts if the rtc interrupt asserts or the wakeup pin is turned on. 0 swr software reset table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 546 freescale semiconductor, inc.
rtc_cr field descriptions (continued) field description 0 no effect. 1 resets all rtc registers except for the swr bit . the swr bit is cleared by por and by software explicitly clearing it. 33.2.6 rtc status register (rtc_sr) address: 4003_d000h base + 14h offset = 4003_d014h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 tce 0 taf tof tif w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 rtc_sr field descriptions field description 31C5 reserved this field is reserved. this read-only field is reserved and always has the value 0. 4 tce time counter enable when time counter is disabled the tsr register and tpr register are writeable, but do not increment. when time counter is enabled the tsr register and tpr register are not writeable, but increment. 0 time counter is disabled. 1 time counter is enabled. 3 reserved this field is reserved. this read-only field is reserved and always has the value 0. 2 taf time alarm flag time alarm flag is set when the tar[tar] equals the tsr[tsr] and the tsr[tsr] increments. this bit is cleared by writing the tar register. 0 time alarm has not occurred. 1 time alarm has occurred. 1 tof time overflow flag time overflow flag is set when the time counter is enabled and overflows. the tsr and tpr do not increment and read as zero when this bit is set. this bit is cleared by writing the tsr register when the time counter is disabled. 0 time overflow has not occurred. 1 time overflow has occurred and time counter is read as zero. table continues on the next page... chapter 33 real time clock (rtc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 547
rtc_sr field descriptions (continued) field description 0 tif time invalid flag the time invalid flag is set on por or software reset. the tsr and tpr do not increment and read as zero when this bit is set. this bit is cleared by writing the tsr register when the time counter is disabled. 0 time is valid. 1 time is invalid and time counter is read as zero. 33.2.7 rtc lock register (rtc_lr) address: 4003_d000h base + 18h offset = 4003_d018h bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 1 lrl srl crl tcl 1 w reset 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 rtc_lr field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 reserved this field is reserved. this read-only field is reserved and always has the value 1. 6 lrl lock register lock after being cleared, this bit can be set only by por or software reset. 0 lock register is locked and writes are ignored. 1 lock register is not locked and writes complete as normal. 5 srl status register lock after being cleared, this bit can be set only by por or software reset. 0 status register is locked and writes are ignored. 1 status register is not locked and writes complete as normal. 4 crl control register lock after being cleared, this bit can only be set by por. 0 control register is locked and writes are ignored. 1 control register is not locked and writes complete as normal. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 548 freescale semiconductor, inc.
rtc_lr field descriptions (continued) field description 3 tcl time compensation lock after being cleared, this bit can be set only by por or software reset. 0 time compensation register is locked and writes are ignored. 1 time compensation register is not locked and writes complete as normal. 2C0 reserved this field is reserved. this read-only field is reserved and always has the value 1. 33.2.8 rtc interrupt enable register (rtc_ier) address: 4003_d000h base + 1ch offset = 4003_d01ch bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 r 0 w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 wpon reserved tsie reserved taie toie tiie w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 rtc_ier field descriptions field description 31C8 reserved this field is reserved. this read-only field is reserved and always has the value 0. 7 wpon wakeup pin on the wakeup pin is optional and not available on all devices. whenever the wakeup pin is enabled and this bit is set, the wakeup pin will assert. 0 no effect. 1 if the wakeup pin is enabled, then the wakeup pin will assert. 6C5 reserved this field is reserved. 4 tsie time seconds interrupt enable the seconds interrupt is an edge-sensitive interrupt with a dedicated interrupt vector. it is generated once a second and requires no software overhead (there is no corresponding status flag to clear). table continues on the next page... chapter 33 real time clock (rtc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 549
rtc_ier field descriptions (continued) field description 0 seconds interrupt is disabled. 1 seconds interrupt is enabled. 3 reserved this field is reserved. 2 taie time alarm interrupt enable 0 time alarm flag does not generate an interrupt. 1 time alarm flag does generate an interrupt. 1 toie time overflow interrupt enable 0 time overflow flag does not generate an interrupt. 1 time overflow flag does generate an interrupt. 0 tiie time invalid interrupt enable 0 time invalid flag does not generate an interrupt. 1 time invalid flag does generate an interrupt. 33.3 functional description 33.3.1 power, clocking, and reset the rtc is an always powered block that remains active in all low power modes. the time counter within the rtc is clocked by a 32.768 khz clock sourced from an external crystal using the oscillator. the power-on-reset signal initializes all rtc registers to their default state. a software reset bit can also initialize all rtc registers. 33.3.1.1 oscillator control the 32.768 khz crystal oscillator is disabled at por and must be enabled by software. after enabling the cystal oscillator, wait the oscillator startup time before setting sr[tce] or using the oscillator clock external to the rtc. the crystal oscillator includes tunable capacitors that can be configured by software. do not change the capacitance unless the oscillator is disabled. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 550 freescale semiconductor, inc.
33.3.1.2 software reset writing one to the cr[swr] forces the equivalent of a por to the rest of the rtc module. the cr[swr] is not affected by the software reset and must be cleared by software. 33.3.1.3 supervisor access when the supervisor access control bit is clear, only supervisor mode software can write to the rtc registers, non-supervisor mode software will generate a bus error. both supervisor and non-supervisor mode software can always read the rtc registers. 33.3.2 time counter the time counter consists of a 32-bit seconds counter that increments once every second and a 16-bit prescaler register that increments once every 32.768 khz clock cycle. the time seconds register and time prescaler register can be written only when sr[tce] is clear. always write to the prescaler register before writing to the seconds register, because the seconds register increments on the falling edge of bit 14 of the prescaler register. the time prescaler register increments provided sr[tce] is set, sr[tif] is clear, sr[tof] is clear, and the 32.768 khz clock source is present. after enabling the oscillator, wait the oscillator startup time before setting sr[tce] to allow time for the oscillator clock output to stabilize. if the time seconds register overflows then the sr[tof] will set and the time prescaler register will stop incrementing. clear sr[tof] by initializing the time seconds register. the time seconds register and time prescaler register read as zero whenever sr[tof] is set. sr[tif] is set on por and software reset and is cleared by initializing the time seconds register. the time seconds register and time prescaler register read as zero whenever sr[tif] is set. 33.3.3 compensation the compensation logic provides an accurate and wide compensation range and can correct errors as high as 3906 ppm and as low as 0.12 ppm. the compensation factor must be calculated externally to the rtc and supplied by software to the compensation chapter 33 real time clock (rtc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 551
register. the rtc itself does not calculate the amount of compensation that is required, although the 1 hz clock is output to an external pin in support of external calibration logic. crystal compensation can be supported by using firmware and crystal characteristics to determine the compensation amount. temperature compensation can be supported by firmware that periodically measures the external temperature via adc and updates the compensation register based on a look-up table that specifies the change in crystal frequency over temperature. the compensation logic alters the number of 32.768 khz clock cycles it takes for the prescaler register to overflow and increment the time seconds counter. the time compensation value is used to adjust the number of clock cycles between -127 and +128. cycles are added or subtracted from the prescaler register when the prescaler register equals 0x3fff and then increments. the compensation interval is used to adjust the frequency at which the time compensation value is used, that is, from once a second to once every 256 seconds. updates to the time compensation register will not take effect until the next time the time seconds register increments and provided the previous compensation interval has expired. when the compensation interval is set to other than once a second then the compensation is applied in the first second interval and the remaining second intervals receive no compensation. compensation is disabled by configuring the time compensation register to zero. 33.3.4 time alarm the time alarm register, sr[taf], and ier[taie] allow the rtc to generate an interrupt at a predefined time. the 32-bit time alarm register is compared with the 32-bit time seconds register each time it increments. the sr[taf] will set when the time alarm register equals the time seconds register and the time seconds register increments. the time alarm flag is cleared by writing the time alarm register. this will usually be the next alarm value, although writing a value that is less than the time seconds register, such as zero, will prevent the time alarm flag from setting again. the time alarm flag cannot otherwise be disabled, although the interrupt it generates is enabled or disabled by ier[taie]. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 552 freescale semiconductor, inc.
33.3.5 update mode the update mode bit in the control register (cr[um]) configures software write access to the time counter enable (sr[tce]) bit. when cr[um] is clear, sr[tce] can be written only when the lr[srl] bit is set. when cr[um] is set, the sr[tce] can also be written when sr[tce] is clear or when sr[tif] or sr[tof] are set. this allows the time seconds and prescaler registers to be initialized whenever time is invalidated, while preventing the time seconds and prescaler registers from being changed on the fly. when lr[srl] is set, cr[um] has no effect on sr[tce]. 33.3.6 register lock the lock register can be used to block write accesses to certain registers until the next por or software reset. locking the control register will disable the software reset. locking the lock register will block future updates to the lock register. write accesses to a locked register are ignored and do not generate a bus error. 33.3.7 interrupt the rtc interrupt is asserted whenever a status flag and the corresponding interrupt enable bit are both set. it is always asserted on por, and software reset. the rtc interrupt is enabled at the chip level by enabling the chip-specific rtc clock gate control bit. the rtc interrupt can be used to wakeup the chip from any low-power mode. the optional rtc seconds interrupt is an edge-sensitive interrupt with a dedicated interrupt vector that is generated once a second and requires no software overhead (there is no corresponding status flag to clear). it is enabled in the rtc by the time seconds interrupt enable bit and enabled at the chip level by setting the chip-specific rtc clock gate control bit. this interrupt is optional and may not be implemented on all devices. chapter 33 real time clock (rtc) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 553
functional description kl04 sub-family reference manual, rev. 3.1, november 2012 554 freescale semiconductor, inc.
chapter 34 serial peripheral interface (spi) 34.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the serial peripheral interface (spi) module provides for full-duplex, synchronous, serial communication between the mcu and peripheral devices. these peripheral devices can include other microcontrollers, analog-to-digital converters, shift registers, sensors, and memories, among others. the spi runs at a baud rate up to the bus clock divided by two in master mode and up to the bus clock divided by four in slave mode. software can poll the status flags, or spi operation can be interrupt driven. note for the actual maximum spi baud rate, refer to the chip configuration details and to the devices data sheet. the spi also includes a hardware match feature for the receive data buffer. the spi includes an internal dma interface to support continuous spi transmission through an on-chip dma controller instead of through the cpu. this feature decreases cpu loading, allowing cpu time to be used for other work. 34.1.1 features the spi includes these distinctive features: ? master mode or slave mode operation ? full-duplex or single-wire bidirectional mode kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 555
? programmable transmit bit rate ? double-buffered transmit and receive data register ? serial clock phase and polarity options ? slave select output ? mode fault error flag with cpu interrupt capability ? control of spi operation during wait mode ? selectable msb-first or lsb-first shifting ? receive data buffer hardware match feature ? support transmission of both transmit and receive by dma 34.1.2 modes of operation the spi functions in three modes, run, wait, and stop. ? run mode this is the basic mode of operation. ? wait mode spi operation in wait mode is a configurable low power mode, controlled by the spiswai bit located in the spix_c2 register. in wait mode, if the spiswai bit is clear, the spi operates like in run mode. if the spiswai bit is set, the spi goes into a power conservative state, with the spi clock generation turned off. if the spi is configured as a master, any transmission in progress stops, but is resumed after cpu enters run mode. if the spi is configured as a slave, reception and transmission of a byte continues, so that the slave stays synchronized to the master. ? stop mode to reduce power consumption, the spi is inactive in stop modes where the peripheral bus clock is stopped but internal logic states are retained. if the spi is configured as a master, any transmission in progress stops, but is resumed after the cpu enters run mode. if the spi is configured as a slave, reception and transmission of a data continues, so that the slave stays synchronized to the master. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 556 freescale semiconductor, inc.
the spi is completely disabled in stop modes where the peripheral bus clock is stopped and internal logic states are not retained. when the cpu wakes from these stop modes, all spi register content is reset. detailed descriptions of operating modes appear in low power mode options . 34.1.3 block diagrams this section includes block diagrams showing spi system connections, the internal organization of the spi module, and the spi clock dividers that control the master mode bit rate. 34.1.3.1 spi system block diagram the following figure shows the spi modules of two mcus connected in a master-slave arrangement. the master device initiates all spi data transfers. during a transfer, the master shifts data out (on the mosi pin) to the slave while simultaneously shifting data in (on the miso pin) from the slave. the transfer effectively exchanges the data that was in the spi shift registers of the two spi systems. the spsck signal is a clock output from the master and an input to the slave. the slave device must be selected by a low level on the slave select input (ss pin). in this system, the master device has configured its ss pin as an optional slave select output. spi shifter master 8 bits clock generator mosi miso miso mosi spsck spsck ss ss slave spi shifter 8 bits figure 34-1. spi system connections chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 557
34.1.3.2 spi module block diagram the following is a block diagram of the spi module. the central element of the spi is the spi shift register. data is written to the double-buffered transmitter (write to spix_d) and gets transferred to the spi shift register at the start of a data transfer. after shifting in 8 bits of data, the data is transferred into the double-buffered receiver where it can be read from spix_d. pin multiplexing logic controls connections between mcu pins and the spi module. when the spi is configured as a master, the clock output is routed to the spsck pin, the shifter output is routed to mosi, and the shifter input is routed from the miso pin. when the spi is configured as a slave, the spsck pin is routed to the clock input of the spi, the shifter output is routed to miso, and the shifter input is routed from the mosi pin. in the external spi system, simply connect all spsck pins to each other, all miso pins together, and all mosi pins together. peripheral devices often use slightly different names for these pins. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 558 freescale semiconductor, inc.
enable spi system shift out shift direction shift clock rx buffer full tx buffer empty shift in tx buffer (write spixd) spi shift register rx buffer (read spixd) pin control master clock slave clock bus rate clock spibr clock generator master/slave mode select clock logic mode fault detection rx dma done rx_dma req tx dma done tx dma req 8-bit comparator spixm master/ slave spsck ss s m s m s m mosi (momi) miso (siso) interrupt request spe lsbfe mstr spmf spmie sptie spie modf txdmae rxdmae sprf sptef mod- ssoe spc0 bidiroe figure 34-2. spi module block diagram without fifo 34.2 external signal description the spi optionally shares four port pins. the function of these pins depends on the settings of spi control bits. when the spi is disabled (spe = 0), these four pins revert to other functions that are not controlled by the spi (based on chip configuration). chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 559
34.2.1 spsck spi serial clock when the spi is enabled as a slave, this pin is the serial clock input. when the spi is enabled as a master, this pin is the serial clock output. 34.2.2 mosi master data out, slave data in when the spi is enabled as a master and spi pin control zero (spc0) is 0 (not bidirectional mode), this pin is the serial data output. when the spi is enabled as a slave and spc0 is 0, this pin is the serial data input. if spc0 is 1 to select single-wire bidirectional mode, and master mode is selected, this pin becomes the bidirectional data i/o pin (momi). also, the bidirectional mode output enable bit determines whether the pin acts as an input (bidiroe is 0) or an output (bidiroe is 1). if spc0 is 1 and slave mode is selected, this pin is not used by the spi and reverts to other functions (based on chip configuration). 34.2.3 miso master data in, slave data out when the spi is enabled as a master and spi pin control zero (spc0) is 0 (not bidirectional mode), this pin is the serial data input. when the spi is enabled as a slave and spc0 is 0, this pin is the serial data output. if spc0 is 1 to select single-wire bidirectional mode, and slave mode is selected, this pin becomes the bidirectional data i/ o pin (siso), and the bidirectional mode output enable bit determines whether the pin acts as an input (bidiroe is 0) or an output (bidiroe is 1). if spc0 is 1 and master mode is selected, this pin is not used by the spi and reverts to other functions (based on chip configuration). 34.2.4 ss slave select when the spi is enabled as a slave, this pin is the low-true slave select input. when the spi is enabled as a master and mode fault enable is off (modfen is 0), this pin is not used by the spi and reverts to other functions (based on chip configuration). when the spi is enabled as a master and modfen is 1, the slave select output enable bit determines whether this pin acts as the mode fault input (ssoe is 0) or as the slave select output (ssoe is 1). external signal description kl04 sub-family reference manual, rev. 3.1, november 2012 560 freescale semiconductor, inc.
memory map and register descriptions the spi has 8-bit registers to select spi options, to control baud rate, to report spi status, to hold an spi data match value, and for transmit/receive data. spi memory map address offset (hex) absolute address (hex) register name width (in bits) access reset value section/ page 0 4007_6000 spi control register 1 (spi0_c1) 8 r/w 04h 34.3.1/561 1 4007_6001 spi control register 2 (spi0_c2) 8 r/w 00h 34.3.2/563 2 4007_6002 spi baud rate register (spi0_br) 8 r/w 00h 34.3.3/564 3 4007_6003 spi status register (spi0_s) 8 r 20h 34.3.4/565 5 4007_6005 spi data register (spi0_d) 8 r/w 00h 34.3.5/566 7 4007_6007 spi match register (spi0_m) 8 r/w 00h 34.3.6/567 34.3.1 spi control register 1 (spi x _c1) this read/write register includes the spi enable control, interrupt enables, and configuration options. address: 4007_6000h base + 0h offset = 4007_6000h bit 7 6 5 4 3 2 1 0 read spie spe sptie mstr cpol cpha ssoe lsbfe write reset 0 0 0 0 0 1 0 0 spi0_c1 field descriptions field description 7 spie spi interrupt enable: for sprf and modf this bit enables the interrupt for spi receive buffer full (sprf) and mode fault (modf) events. 0 interrupts from sprf and modf are inhibiteduse polling 1 request a hardware interrupt when sprf or modf is 1 6 spe spi system enable this bit enables the spi system and dedicates the spi port pins to spi system functions. if spe is cleared, the spi is disabled and forced into an idle state, and all status bits in the s register are reset. table continues on the next page... 34.3 chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 561
spi0_c1 field descriptions (continued) field description 0 spi system inactive 1 spi system enabled 5 sptie spi transmit interrupt enable this is the interrupt enable bit for spi transmit buffer empty (sptef). an interrupt occurs when the spi transmit buffer is empty (sptef is set). 0 interrupts from sptef inhibited (use polling) 1 when sptef is 1, hardware interrupt requested 4 mstr master/slave mode select this bit selects master or slave mode operation. 0 spi module configured as a slave spi device 1 spi module configured as a master spi device 3 cpol clock polarity this bit selects an inverted or non-inverted spi clock. to transmit data between spi modules, the spi modules must have identical cpol values. this bit effectively places an inverter in series with the clock signal either from a master spi device or to a slave spi device. refer to the description of spi clock formats for details. 0 active-high spi clock (idles low) 1 active-low spi clock (idles high) 2 cpha clock phase this bit selects one of two clock formats for different kinds of synchronous serial peripheral devices. refer to the description of spi clock formats for details. 0 first edge on spsck occurs at the middle of the first cycle of a data transfer 1 first edge on spsck occurs at the start of the first cycle of a data transfer 1 ssoe slave select output enable this bit is used in combination with the mode fault enable (modfen) bit in the c2 register and the master/ slave (mstr) control bit to determine the function of the ss pin. 0 when modfen is 0: in master mode, ss pin function is general-purpose i/o (not spi). in slave mode, ss pin function is slave select input. when modfen is 1: in master mode, ss pin function is ss input for mode fault. in slave mode, ss pin function is slave select input. 1 when modfen is 0: in master mode, ss pin function is general-purpose i/o (not spi). in slave mode, ss pin function is slave select input. when modfen is 1: in master mode, ss pin function is automatic ss output. in slave mode: ss pin function is slave select input. 0 lsbfe lsb first (shifter direction) this bit does not affect the position of the msb and lsb in the data register. reads and writes of the data register always have the msb in bit 7. 0 spi serial data transfers start with most significant bit 1 spi serial data transfers start with least significant bit memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 562 freescale semiconductor, inc.
34.3.2 spi control register 2 (spi x _c2) this read/write register is used to control optional features of the spi system. bit 6 is not implemented and always reads 0. address: 4007_6000h base + 1h offset = 4007_6001h bit 7 6 5 4 3 2 1 0 read spmie reserved txdmae modfen bidiroe rxdmae spiswai spc0 write reset 0 0 0 0 0 0 0 0 spi0_c2 field descriptions field description 7 spmie spi match interrupt enable this is the interrupt enable bit for the spi receive data buffer hardware match (spmf) function. 0 interrupts from spmf inhibited (use polling) 1 when spmf is 1, requests a hardware interrupt 6 reserved this field is reserved. do not write to this reserved bit. 5 txdmae transmit dma enable this bit enables a transmit dma request. when this bit is set to 1, a transmit dma request is asserted when both sptef and spe are set, and the interrupt from sptef is disabled. 0 dma request for transmit is disabled and interrupt from sptef is allowed 1 dma request for transmit is enabled and interrupt from sptef is disabled 4 modfen master mode-fault function enable when the spi is configured for slave mode, this bit has no meaning or effect. (the ss pin is the slave select input.) in master mode, this bit determines how the ss pin is used. for details, refer to the description of the ssoe bit in the c1 register. 0 mode fault function disabled, master ss pin reverts to general-purpose i/o not controlled by spi 1 mode fault function enabled, master ss pin acts as the mode fault input or the slave select output 3 bidiroe bidirectional mode output enable when bidirectional mode is enabled because spi pin control 0 (spc0) is set to 1, the bidiroe bit determines whether the spi data output driver is enabled to the single bidirectional spi i/o pin. depending on whether the spi is configured as a master or a slave, it uses the mosi (momi) or miso (siso) pin, respectively, as the single spi data i/o pin. when spc0 is 0, bidiroe has no meaning or effect. 0 output driver disabled so spi data i/o pin acts as an input 1 spi i/o pin enabled as an output 2 rxdmae receive dma enable this is the enable bit for a receive dma request. when this bit is set to 1, a receive dma request is asserted when both sprf and spe are set, and the interrupt from sprf is disabled. table continues on the next page... chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 563
spi0_c2 field descriptions (continued) field description 0 dma request for receive is disabled and interrupt from sprf is allowed 1 dma request for receive is enabled and interrupt from sprf is disabled 1 spiswai spi stop in wait mode this bit is used for power conservation while the device is in wait mode. 0 spi clocks continue to operate in wait mode 1 spi clocks stop when the mcu enters wait mode 0 spc0 spi pin control 0 this bit enables bidirectional pin configurations. 0 spi uses separate pins for data input and data output (pin mode is normal). in master mode of operation: miso is master in and mosi is master out. in slave mode of operation: miso is slave out and mosi is slave in. 1 spi configured for single-wire bidirectional operation (pin mode is bidirectional). in master mode of operation: miso is not used by spi; mosi is master in when bidiroe is 0 or master i/o when bidiroe is 1. in slave mode of operation: miso is slave in when bidiroe is 0 or slave i/o when bidiroe is 1; mosi is not used by spi. 34.3.3 spi baud rate register (spi x _br) use this register to set the prescaler and bit rate divisor for an spi master. this register may be read or written at any time. address: 4007_6000h base + 2h offset = 4007_6002h bit 7 6 5 4 3 2 1 0 read 0 sppr[2:0] spr[3:0] write reset 0 0 0 0 0 0 0 0 spi0_br field descriptions field description 7 reserved this field is reserved. this read-only field is reserved and always has the value 0. 6C4 sppr[2:0] spi baud rate prescale divisor this 3-bit field selects one of eight divisors for the spi baud rate prescaler. the input to this prescaler is the bus rate clock (busclk). the output of this prescaler drives the input of the spi baud rate divider. refer to the description of spi baud rate generation for details. 000 baud rate prescaler divisor is 1 table continues on the next page... memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 564 freescale semiconductor, inc.
spi0_br field descriptions (continued) field description 001 baud rate prescaler divisor is 2 010 baud rate prescaler divisor is 3 011 baud rate prescaler divisor is 4 100 baud rate prescaler divisor is 5 101 baud rate prescaler divisor is 6 110 baud rate prescaler divisor is 7 111 baud rate prescaler divisor is 8 3C0 spr[3:0] spi baud rate divisor this 4-bit field selects one of nine divisors for the spi baud rate divider. the input to this divider comes from the spi baud rate prescaler. refer to the description of spi baud rate generation for details. 0000 baud rate divisor is 2 0001 baud rate divisor is 4 0010 baud rate divisor is 8 0011 baud rate divisor is 16 0100 baud rate divisor is 32 0101 baud rate divisor is 64 0110 baud rate divisor is 128 0111 baud rate divisor is 256 1000 baud rate divisor is 512 all others reserved 34.3.4 spi status register (spi x _s) this register contains read-only status bits. writes have no meaning or effect. note bits 3 through 0 are not implemented and always read 0. address: 4007_6000h base + 3h offset = 4007_6003h bit 7 6 5 4 3 2 1 0 read sprf spmf sptef modf 0 write reset 0 0 1 0 0 0 0 0 spi0_s field descriptions field description 7 sprf spi read buffer full flag sprf is set at the completion of an spi transfer to indicate that received data may be read from the spi data (d) register. when the receive dma request is disabled (rxdmae is 0), sprf is cleared by reading sprf while it is set and then reading the spi data register. when the receive dma request is enabled (rxdmae is 1), sprf is automatically cleared when the dma transfer for the receive dma request is completed (rx dma done is asserted). table continues on the next page... chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 565
spi0_s field descriptions (continued) field description 0 no data available in the receive data buffer 1 data available in the receive data buffer 6 spmf spi match flag spmf is set after sprf is 1 when the value in the receive data buffer matches the value in the m register. to clear the flag, read spmf when it is set and then write a 1 to it. 0 value in the receive data buffer does not match the value in the m register 1 value in the receive data buffer matches the value in the m register 5 sptef spi transmit buffer empty flag this bit is set when the transmit data buffer is empty. when the transmit dma request is disabled (txdmae is 0), sptef is cleared by reading the s register with sptef set and then writing a data value to the transmit buffer at d. the s register must be read with sptef set to 1 before writing data to the d register; otherwise, the d write is ignored. when the transmit dma request is enabled (txdmae is 1), sptef is automatically cleared when the dma transfer for the transmit dma request is completed (tx dma done is asserted). sptef is automatically set when all data from the transmit buffer transfers into the transmit shift register. for an idle spi, data written to d is transferred to the shifter almost immediately so that sptef is set within two bus cycles, allowing a second set of data to be queued into the transmit buffer. after completion of the transfer of the data in the shift register, the queued data from the transmit buffer automatically moves to the shifter, and sptef is set to indicate that room exists for new data in the transmit buffer. if no new data is waiting in the transmit buffer, sptef simply remains set and no data moves from the buffer to the shifter. if a transfer does not stop, the last data that was transmitted is sent out again. 0 spi transmit buffer not empty 1 spi transmit buffer empty 4 modf master mode fault flag modf is set if the spi is configured as a master and the slave select input goes low, indicating some other spi device is also configured as a master. the ss pin acts as a mode fault error input only when mstr is 1, modfen is 1, and ssoe is 0; otherwise, modf will never be set. modf is cleared by reading modf while it is 1 and then writing to the spi control register 1 (c1). 0 no mode fault error 1 mode fault error detected 3C0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 34.3.5 spi data register (spi x _d) this register is both the input and output register for spi data. a write to the register writes to the transmit data buffer, allowing data to be queued and transmitted. when the spi is configured as a master, data queued in the transmit data buffer is transmitted immediately after the previous transmission has completed. memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 566 freescale semiconductor, inc.
the sptef bit in the s register indicates when the transmit data buffer is ready to accept new data. when the transmit dma request is disabled (txdmae is 0): the s register must be read when sptef is set before writing to the spi data register; otherwise, the write is ignored. when the transmit dma request is enabled (txdmae is 1) when sptef is set, the spi data register can be written automatically by dma without reading the s register first. data may be read from the spi data register any time after sprf is set and before another transfer is finished. failure to read the data out of the receive data buffer before a new transfer ends causes a receive overrun condition, and the data from the new transfer is lost. the new data is lost because the receive buffer still held the previous character and was not ready to accept the new data. there is no indication for a receive overrun condition, so the application system designer must ensure that previous data has been read from the receive buffer before a new transfer is initiated. address: 4007_6000h base + 5h offset = 4007_6005h bit 7 6 5 4 3 2 1 0 read bits[7:0] write reset 0 0 0 0 0 0 0 0 spi0_d field descriptions field description 7C0 bits[7:0] data (low byte) 34.3.6 spi match register (spi x _m) this register contains the hardware compare value. when the value received in the spi receive data buffer equals this hardware compare value, the spi match flag (spmf) sets. address: 4007_6000h base + 7h offset = 4007_6007h bit 7 6 5 4 3 2 1 0 read bits[7:0] write reset 0 0 0 0 0 0 0 0 spi0_m field descriptions field description 7C0 bits[7:0] hardware compare value (low byte) chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 567
34.4 functional description this section provides the functional description of the module. 34.4.1 general the spi system is enabled by setting the spi enable (spe) bit in spi control register 1. while the spe bit is set, the four associated spi port pins are dedicated to the spi function as: ? slave select (ss) ? serial clock (spsck) ? master out/slave in (mosi) ? master in/slave out (miso) an spi transfer is initiated in the master spi device by reading the spi status register (spix_s) when sptef = 1 and then writing data to the transmit data buffer (write to spixd ). when a transfer is complete, received data is moved into the receive data buffer. the spixd register acts as the spi receive data buffer for reads and as the spi transmit data buffer for writes. the clock phase control bit (cpha) and clock polarity control bit (cpol) in the spi control register 1 (spix_c1) select one of four possible clock formats to be used by the spi system. the cpol bit simply selects a non-inverted or inverted clock. the cpha bit is used to accommodate two fundamentally different protocols by sampling data on odd numbered spsck edges or on even numbered spsck edges. the spi can be configured to operate as a master or as a slave. when the mstr bit in spi control register 1 is set, master mode is selected; when the mstr bit is clear, slave mode is selected. 34.4.2 master mode the spi operates in master mode when the mstr bit is set. only a master spi module can initiate transmissions. a transmission begins by reading the spix_s register while sptef = 1 and writing to the master spi data registers. if the shift register is empty, the byte immediately transfers to the shift register. the data begins shifting out on the mosi pin under the control of the serial clock. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 568 freescale semiconductor, inc.
? spsck ? the spr3, spr2, spr1, and spr0 baud rate selection bits in conjunction with the sppr2, sppr1, and sppr0 baud rate preselection bits in the spi baud rate register control the baud rate generator and determine the speed of the transmission. the spsck pin is the spi clock output. through the spsck pin, the baud rate generator of the master controls the shift register of the slave peripheral. ? mosi, miso pin ? in master mode, the function of the serial data output pin (mosi) and the serial data input pin (miso) is determined by the spc0 and bidiroe control bits. ? ss pin ? if modfen and ssoe bit are set, the ss pin is configured as slave select output. the ss output becomes low during each transmission and is high when the spi is in idle state. if modfen is set and ssoe is cleared, the ss pin is configured as input for detecting mode fault error. if the ss input becomes low this indicates a mode fault error where another master tries to drive the mosi and spsck lines. in this case, the spi immediately switches to slave mode by clearing the mstr bit and also disables the slave output buffer miso (or siso in bidirectional mode). as a result, all outputs are disabled, and spsck, mosi and miso are inputs. if a transmission is in progress when the mode fault occurs, the transmission is aborted and the spi is forced into idle state. this mode fault error also sets the mode fault (modf) flag in the spi status register (spix_s). if the spi interrupt enable bit (spie) is set when the modf flag gets set, then an spi interrupt sequence is also requested. when a write to the spi data register in the master occurs, there is a half spsck-cycle delay. after the delay, spsck is started within the master. the rest of the transfer operation differs slightly, depending on the clock format specified by the spi clock phase bit, cpha, in spi control register 1 (see spi clock formats ). note a change of the bits cpol, cpha, ssoe, lsbfe, modfen, spc0, bidiroe with spc0 set, sppr2-sppr0 and spr3- spr0 in master mode abort a transmission in progress and force the spi into idle state. the remote slave cannot detect this, therefore the master has to ensure that the remote slave is set back to idle state. chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 569
34.4.3 slave mode the spi operates in slave mode when the mstr bit in spi control register1 is clear. ? spsck in slave mode, spsck is the spi clock input from the master. ? miso, mosi pin in slave mode, the function of the serial data output pin (miso) and serial data input pin (mosi) is determined by the spc0 bit and bidiroe bit in spi control register 2. ? ss pin the ss pin is the slave select input. before a data transmission occurs, the ss pin of the slave spi must be low. ss must remain low until the transmission is complete. if ss goes high, the spi is forced into an idle state. the ss input also controls the serial data output pin. if ss is high (not selected), the serial data output pin is high impedance. if ss is low, the first bit in the spi data register is driven out of the serial data output pin. also, if the slave is not selected (ss is high), then the spsck input is ignored and no internal shifting of the spi shift register occurs. although the spi is capable of duplex operation, some spi peripherals are capable of only receiving spi data in a slave mode. for these simpler devices, there is no serial data out pin. note when peripherals with duplex capability are used, take care not to simultaneously enable two receivers whose serial outputs drive the same system slave's serial data output line. as long as no more than one slave device drives the system slave's serial data output line, it is possible for several slaves to receive the same transmission from a master, although the master would not receive return information from all of the receiving slaves. if the cpha bit in spi control register 1 is clear, odd numbered edges on the spsck input cause the data at the serial data input pin to be latched. even numbered edges cause the value previously latched from the serial data input pin to shift into the lsb or msb of the spi shift register, depending on the lsbfe bit. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 570 freescale semiconductor, inc.
if the cpha bit is set, even numbered edges on the spsck input cause the data at the serial data input pin to be latched. odd numbered edges cause the value previously latched from the serial data input pin to shift into the lsb or msb of the spi shift register, depending on the lsbfe bit. when cpha is set, the first edge is used to get the first data bit onto the serial data output pin. when cpha is clear and the ss input is low (slave selected), the first bit of the spi data is driven out of the serial data output pin. after the eighth shift, the transfer is considered complete and the received data is transferred into the spi data register. to indicate transfer is complete, the sprf flag in the spi status register is set. note a change of the bits bidiroe with spc0 set, cpol, cpha, ssoe, lsbfe, modfen, and spc0 in slave mode will corrupt a transmission in progress and must be avoided. 34.4.4 spi transmission by dma spi supports both transmit and receive by dma. the basic flow of spi transmission by dma is as below. configure spi before transmission reset configure dma controller for spi transmission set txdmae/rxdmae=1 to enable transmit/receive by dma set spe=1 to start transmission in master mode or enable spi for transmission in slave moe wait for interrupt(s) of dma controller indicating end of spi transmission figure 34-15. basic flow of spi transmission by dma chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 571
34.4.4.1 transmit by dma transmit by dma is supported only when txdmae is set. a transmit dma request is asserted when both spe and sptef are set. then the on-chip dma controller detects this request and transfers data from memory into the spi data register. after that, tx dma done is asserted to clear sptef automatically. this process repeats until all data for transmission (the number is decided by the configuration register[s] of the dma controller) is sent. after dma transfers the first byte to the spi data register, the spi pushes this data into the shifter, thereby making sptef high again. this generates another dma request immediately, but the cpu lacks enough time to service the first dma interrupt service request (isr). the subsequent dma request is paced at the spi transfer rate. manage this behavior during the first byte transfer through the dma channel. write the first byte to the spi data register via the cpu. the other bytes are transmitted by the dma. configure spi before transmission reset configure dma controller for spi transmission set spe=1 to start transmission in master mode or enable spi for transmission in slave mode wait for interrupt(s) of dma controller indicating end of spi transmission read spi status register write the first byte to spi data register via cpu set txdmae to enable transmit by dma figure 34-16. recommended startup of spi transmit by dma functional description kl04 sub-family reference manual, rev. 3.1, november 2012 572 freescale semiconductor, inc.
34.4.4.2 receive by dma receive by dma is supported only when rxdmae is set. a receive dma request is asserted when both spe and sprf are set. then the on-chip dma controller detects this request and transfers data from the spi data register into memory. after that, rx dma done is asserted to clear sprf automatically. this process repeats until all data to be received (the number is decided by configuration register[s] of the dma controller) is received or no receive dma request is generated again because the spi transmission is finished. 34.4.5 spi clock formats to accommodate a wide variety of synchronous serial peripherals from different manufacturers, the spi system has a clock polarity (cpol) bit and a clock phase (cpha) control bit to select one of four clock formats for data transfers. cpol selectively inserts an inverter in series with the clock. cpha chooses between two different clock phase relationships between the clock and data. the following figure shows the clock formats when cpha = 1. at the top of the figure, the eight bit times are shown for reference with bit 1 starting at the first spsck edge and bit 8 ending one-half spsck cycle after the eighth spsck edge. the msb first and lsb first lines show the order of spi data bits depending on the setting in lsbfe. both variations of spsck polarity are shown, but only one of these waveforms applies for a specific transfer, depending on the value in cpol. the sample in waveform applies to the mosi input of a slave or the miso input of a master. the mosi waveform applies to the mosi output pin from a master and the miso waveform applies to the miso output from a slave. the ss out waveform applies to the slave select output from a master (provided modfen and ssoe = 1). the master ss output goes to active low one-half spsck cycle before the start of the transfer and goes back high at the end of the eighth bit time of the transfer. the ss in waveform applies to the slave select input of a slave. chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 573
ss out ss in (slave) (master) (slave out) miso msb first lsb first mosi (master out) (miso or mosi) sample in spsck (cpol = 1) spsck (cpol = 0) bit time # (reference) bit 7 bit 0 bit 6 bit 1 bit 2 bit 5 bit 0 bit 7 bit 1 bit 6 1 2 6 7 8 ... ... ... figure 34-17. spi clock formats (cpha = 1) when cpha = 1, the slave begins to drive its miso output when ss goes to active low, but the data is not defined until the first spsck edge. the first spsck edge shifts the first bit of data from the shifter onto the mosi output of the master and the miso output of the slave. the next spsck edge causes both the master and the slave to sample the data bit values on their miso and mosi inputs, respectively. at the third spsck edge, the spi shifter shifts one bit position which shifts in the bit value that was just sampled, and shifts the second data bit value out the other end of the shifter to the mosi and miso outputs of the master and slave, respectively. when cpha = 1, the slave's ss input is not required to go to its inactive high level between transfers. in this clock format, a back-to-back transmission can occur, as follows: 1. a transmission is in progress. 2. a new data byte is written to the transmit buffer before the in-progress transmission is complete. 3. when the in-progress transmission is complete, the new, ready data byte is transmitted immediately. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 574 freescale semiconductor, inc.
between these two successive transmissions, no pause is inserted; the ss pin remains low. the following figure shows the clock formats when cpha = 0. at the top of the figure, the eight bit times are shown for reference with bit 1 starting as the slave is selected (ss in goes low), and bit 8 ends at the last spsck edge. the msb first and lsb first lines show the order of spi data bits depending on the setting in lsbfe. both variations of spsck polarity are shown, but only one of these waveforms applies for a specific transfer, depending on the value in cpol. the sample in waveform applies to the mosi input of a slave or the miso input of a master. the mosi waveform applies to the mosi output pin from a master and the miso waveform applies to the miso output from a slave. the ss out waveform applies to the slave select output from a master (provided modfen and ssoe = 1). the master ss output goes to active low at the start of the first bit time of the transfer and goes back high one-half spsck cycle after the end of the eighth bit time of the transfer. the ss in waveform applies to the slave select input of a slave. ss out ss in (slave) (master) (slave out) miso msb first lsb first mosi (master out) (miso or mosi) sample in spsck (cpol = 1) spsck (cpol = 0) bit time # (reference) bit 7 bit 0 bit 6 bit 1 bit 2 bit 5 bit 0 bit 7 bit 1 bit 6 1 2 6 7 8 ... ... ... figure 34-18. spi clock formats (cpha = 0) chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 575
when cpha = 0, the slave begins to drive its miso output with the first data bit value (msb or lsb depending on lsbfe) when ss goes to active low. the first spsck edge causes both the master and the slave to sample the data bit values on their miso and mosi inputs, respectively. at the second spsck edge, the spi shifter shifts one bit position which shifts in the bit value that was just sampled and shifts the second data bit value out the other end of the shifter to the mosi and miso outputs of the master and slave, respectively. when cpha = 0, the slave's ss input must go to its inactive high level between transfers. 34.4.6 spi baud rate generation as shown in the following figure, the clock source for the spi baud rate generator is the bus clock. the three prescale bits (sppr2:sppr1:sppr0) choose a prescale divisor of 1, 2, 3, 4, 5, 6, 7, or 8. the three rate select bits (spr3:spr2:spr1:spr0) divide the output of the prescaler stage by 2, 4, 8, 16, 32, 64, 128, 256, or 512 to get the internal spi master mode bit-rate clock. the baud rate generator is activated only when the spi is in the master mode and a serial transfer is taking place. in the other cases, the divider is disabled to decrease i dd current. the baud rate divisor equation is as follows (except those reserved combinations in the spi baud rate divisor table). baudratedivisor = (sppr + 1) 2 (spr + 1) the baud rate can be calculated with the following equation: baudrate = busclock / baudratedivisor master spi bit rate baud rate divider prescaler bus clock sppr2:sppr1:sppr0 spr3:spr2:spr1:spr0 divide by 1, 2, 3, 4, 5, 6, 7, or 8 divide by 2, 4, 8, 16, 32, 64, 128, 256, or 512 figure 34-19. spi baud rate generation 34.4.7 special features the following section shows the module special features. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 576 freescale semiconductor, inc.
34.4.7.1 ss output the ss output feature automatically drives the ss pin low during transmission to select external devices and drives the ss pin high during idle to deselect external devices. when the ss output is selected, the ss output pin is connected to the ss input pin of the external device. the ss output is available only in master mode during normal spi operation by asserting the ssoe and modfen bits as shown in the description of the c1[ssoe] bit. the mode fault feature is disabled while ss output is enabled. note be careful when using the ss output feature in a multimaster system because the mode fault feature is not available for detecting system errors between masters. 34.4.7.2 bidirectional mode (momi or siso) the bidirectional mode is selected when the spc0 bit is set in spi control register 2 (see the following table). in this mode, the spi uses only one serial data pin for the interface with one or more external devices. the mstr bit decides which pin to use. the mosi pin becomes the serial data i/o (momi) pin for the master mode, and the miso pin becomes serial data i/o (siso) pin for the slave mode. the miso pin in master mode and mosi pin in slave mode are not used by the spi. table 34-15. normal mode and bidirectional mode when spe = 1 master mode mstr = 1 slave mode mstr = 0 normal mode spc0 = 0 mosi miso serial out spi serial in mosi miso serial out spi serial in bidirectional mode spc0 = 1 serial out spi serial in momi bidiroe serial out spi serial in siso bidiroe the direction of each serial i/o pin depends on the bidiroe bit. if the pin is configured as an output, serial data from the shift register is driven out on the pin. the same pin is also the serial input to the shift register. the spsck is an output for the master mode and an input for the slave mode. chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 577
ss is the input or output for the master mode, and it is always the input for the slave mode. the bidirectional mode does not affect spsck and ss functions. note in bidirectional master mode, with the mode fault feature enabled, both data pins miso and mosi can be occupied by the spi, though mosi is normally used for transmissions in bidirectional mode and miso is not used by the spi. if a mode fault occurs, the spi is automatically switched to slave mode. in this case, miso becomes occupied by the spi and mosi is not used. consider this scenario if the miso pin is used for another purpose. 34.4.8 error conditions the spi module has one error condition: the mode fault error. 34.4.8.1 mode fault error if the ss input becomes low while the spi is configured as a master, it indicates a system error where more than one master may be trying to drive the mosi and spsck lines simultaneously. this condition is not permitted in normal operation, and it sets the modf bit in the spi status register automatically provided that the modfen bit is set. in the special case where the spi is in master mode and the modfen bit is cleared, the ss pin is not used by the spi. in this special case, the mode fault error function is inhibited and modf remains cleared. if the spi system is configured as a slave, the ss pin is a dedicated input pin. a mode fault error does not occur in slave mode. if a mode fault error occurs, the spi is switched to slave mode, with the exception that the slave output buffer is disabled. so the spsck, miso and mosi pins are forced to be high impedance inputs to avoid any possibility of conflict with another output driver. a transmission in progress is aborted and the spi is forced into idle state. if the mode fault error occurs in the bidirectional mode for an spi system configured in master mode, the output enable of momi (mosi in bidirectional mode) is cleared if it was set. no mode fault error occurs in the bidirectional mode for the spi system configured in slave mode. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 578 freescale semiconductor, inc.
the mode fault flag is cleared automatically by a read of the spi status register (with modf set) followed by a write to spi control register 1. if the mode fault flag is cleared, the spi becomes a normal master or slave again. 34.4.9 low power mode options this section describes the low power mode options. 34.4.9.1 spi in run mode in run mode, with the spi system enable (spe) bit in the spi control register clear, the spi system is in a low-power, disabled state. spi registers can still be accessed, but clocks to the core of this module are disabled. 34.4.9.2 spi in wait mode spi operation in wait mode depends upon the state of the spiswai bit in spi control register 2. ? if spiswai is clear, the spi operates normally when the cpu is in wait mode. ? if spiswai is set, spi clock generation ceases and the spi module enters a power conservation state when the cpu is in wait mode. ? if spiswai is set and the spi is configured for master, any transmission and reception in progress stops at wait mode entry. the transmission and reception resumes when the spi exits wait mode. ? if spiswai is set and the spi is configured as a slave, any transmission and reception in progress continues if the spsck continues to be driven from the master. this keeps the slave synchronized to the master and the spsck. if the master transmits data while the slave is in wait mode, the slave continues to send data consistent with the operation mode at the start of wait mode (that is, if the slave is currently sending its spix_d to the master, it continues to send the same byte. otherwise, if the slave is currently sending the last data received byte from the master, it continues to send each previously received data from the master byte). chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 579
note care must be taken when expecting data from a master while the slave is in a wait mode or a stop mode where the peripheral bus clock is stopped but internal logic states are retained. even though the shift register continues to operate, the rest of the spi is shut down (that is, an sprf interrupt is not generated until an exit from stop or wait mode). also, the data from the shift register is not copied into the spix_d registers until after the slave spi has exited wait or stop mode. an sprf flag and spix_d copy is only generated if wait mode is entered or exited during a transmission. if the slave enters wait mode in idle mode and exits wait mode in idle mode, neither an sprf nor a spix_d copy occurs. 34.4.9.3 spi in stop mode operation in a stop mode where the peripheral bus clock is stopped but internal logic states are retained depends on the spi system. the stop mode does not depend on the spiswai bit. upon entry to this type of stop mode, the spi module clock is disabled (held high or low). ? if the spi is in master mode and exchanging data when the cpu enters the stop mode, the transmission is frozen until the cpu exits stop mode. after the exit from stop mode, data to and from the external spi is exchanged correctly. ? in slave mode, the spi remains synchronized with the master. the spi is completely disabled in a stop mode where the peripheral bus clock is stopped and internal logic states are not retained. after an exit from this type of stop mode, all registers are reset to their default values, and the spi module must be re-initialized. 34.4.10 reset the reset values of registers and signals are described in the memory map and register descriptions content, which details the registers and their bitfields. ? if a data transmission occurs in slave mode after a reset without a write to spix_d, the transmission consists of "garbage" or the data last received from the master before the reset. ? reading from spix_d after reset always returns zeros. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 580 freescale semiconductor, inc.
34.4.11 interrupts the spi originates interrupt requests only when the spi is enabled (the spe bit in the spix_c1 register is set). the following is a description of how the spi makes a request and how the mcu should acknowledge that request. the interrupt vector offset and interrupt priority are chip dependent. four flag bits, three interrupt mask bits, and one interrupt vector are associated with the spi system. the spi interrupt enable mask (spie) enables interrupts from the spi receiver full flag (sprf) and mode fault flag (modf). the spi transmit interrupt enable mask (sptie) enables interrupts from the spi transmit buffer empty flag (sptef). the spi match interrupt enable mask bit (spimie) enables interrupts from the spi match flag (spmf). when one of the flag bits is set, and the associated interrupt mask bit is set, a hardware interrupt request is sent to the cpu. if the interrupt mask bits are cleared, software can poll the associated flag bits instead of using interrupts. the spi interrupt service routine (isr) should check the flag bits to determine which event caused the interrupt. the service routine should also clear the flag bit(s) before returning from the isr (usually near the beginning of the isr). 34.4.11.1 modf modf occurs when the master detects an error on the ss pin. the master spi must be configured for the modf feature (see the description of the c1[ssoe] bit). once modf is set, the current transfer is aborted and the master (mstr) bit in the spix_c1 register resets to 0. the modf interrupt is reflected in the status register's modf flag. clearing the flag also clears the interrupt. this interrupt stays active while the modf flag is set. modf has an automatic clearing process that is described in the spi status register. 34.4.11.2 sprf sprf occurs when new data has been received and copied to the spi receive data buffer. after sprf is set, it does not clear until it is serviced. sprf has an automatic clearing process that is described in the spi status register details. if the sprf is not serviced before the end of the next transfer (that is, sprf remains active throughout another transfer), the subsequent transfers are ignored and no new data is copied into the data register. chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 581
34.4.11.3 sptef sptef occurs when the spi transmit buffer is ready to accept new data. after sptef is set, it does not clear until it is serviced. sptef has an automatic clearing process that is described in the spi status register details. 34.4.11.4 spmf spmf occurs when the data in the receive data buffer is equal to the data in the spi match register. 34.4.11.5 asynchronous interrupt in low power modes when the cpu is in wait mode or stop mode and the spi module receives a transmission, the spi module can generate an asynchronous interrupt to wake the cpu from the low power mode. the module generates the asynchronous interrupt only when all of the following conditions apply: 1. the c1[spie] bit is set to 1. 2. the cpu is in wait modein which case the c2[spiswai] bit must be 1or in stop mode where the peripheral bus clock is stopped but internal logic states are retained. 3. the spi module is in slave mode. 4. the received transmission ends. after the interrupt wakes the cpu and the peripheral bus clock is active again, the spi module copies the received data from the shifter into the data register and generates flags or dma request signals. during the wakeup phase, a continuous transmission from a master would destroy the first received data. 34.5 initialization/application information this section discusses an example of how to initialize and use the spi. 34.5.1 initialization sequence before the spi module can be used for communication, an initialization procedure must be carried out, as follows: initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 582 freescale semiconductor, inc.
1. update control register 1 (spix_c1) to enable the spi and to control interrupt enables. this register also sets the spi as master or slave, determines clock phase and polarity, and configures the main spi options. 2. update control register 2 (spix_c2) to enable additional spi functions such as the spi match interrupt feature, the master mode-fault function, and bidirectional mode output as well as to control and other optional features. 3. update the baud rate register (spix_br) to set the prescaler and bit rate divisor for an spi master. 4. update the hardware match register (spix_m) with the value to be compared to the receive data register for triggering an interrupt if hardware match interrupts are enabled. 5. in the master, read spix_s while sptef = 1, and then write to the transmit data register (spix_d) to begin transfer. 34.5.2 pseudo-code example in this example, the spi module is set up for master mode with only hardware match interrupts enabled. the spi runs at a maximum baud rate of bus clock divided by 2. clock phase and polarity are set for an active-high spi clock where the first edge on spsck occurs at the start of the first cycle of a data transfer. spix_c1=0x54(%01010100) bit 7 spie = 0 disables receive and mode fault interrupts bit 6 spe = 1 enables the spi system bit 5 sptie = 0 disables spi transmit interrupts bit 4 mstr = 1 sets the spi module as a master spi device bit 3 cpol = 0 configures spi clock as active-high bit 2 cpha = 1 first edge on spsck at start of first data transfer cycle bit 1 ssoe = 0 determines ss pin function when mode fault enabled bit 0 lsbfe = 0 spi serial data transfers start with most significant bit spix_c2 = 0x80(%10000000) bit 7 spmie = 1 spi hardware match interrupt enabled bit 6 = 0 unimplemented bit 5 txdmae = 0 dma request disabled bit 4 modfen = 0 disables mode fault function bit 3 bidiroe = 0 spi data i/o pin acts as input table continues on the next page... chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 583
spix_c2 = 0x80(%10000000) bit 2 rxdmae = 0 dma request disabled bit 1 spiswai = 0 spi clocks operate in wait mode bit 0 spc0 = 0 uses separate pins for data input and output spix_br = 0x00(%00000000) bit 7 = 0 reserved bit 6:4 = 000 sets prescale divisor to 1 bit 3:0 = 0000 sets baud rate divisor to 2 spix_s = 0x00(%00000000) bit 7 sprf = 0 flag is set when receive data buffer is full bit 6 spmf = 0 flag is set when spix_m = receive data buffer bit 5 sptef = 0 flag is set when transmit data buffer is empty bit 4 modf = 0 mode fault flag for master mode bit 3:0 = 0 reserved spix_m = 0xxx holds bits 0C7 of the hardware match buffer. spix_d = 0xxx holds bits 0C7 of the data to be transmitted by the transmit buffer and received by the receive buffer. initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 584 freescale semiconductor, inc.
reset continue read spmf while set to clear flag, then write a 1 to it yes spmf = 1 ? no no no yes yes yes read write to sprf = 1 ? sptef = 1 ? initialize spi spixc1 = 0x54 spixc2 = spixbr = 0x00 0x80 spixd spixd figure 34-20. initialization flowchart example for spi master device chapter 34 serial peripheral interface (spi) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 585
initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 586 freescale semiconductor, inc.
chapter 35 inter-integrated circuit (i2c) 35.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the inter-integrated circuit (i 2 c, i2c, or iic) module provides a method of communication between a number of devices. the interface is designed to operate up to 100 kbit/s with maximum bus loading and timing. the i2c device is capable of operating at higher baud rates, up to a maximum of clock/20, with reduced bus loading. the maximum communication length and the number of devices that can be connected are limited by a maximum bus capacitance of 400 pf. the i2c module also complies with the system management bus (smbus) specification, version 2 . 35.1.1 features the i2c module has the following features: ? compatible with the i 2 c-bus specification ? multimaster operation ? software programmable for one of 64 different serial clock frequencies ? software-selectable acknowledge bit ? interrupt-driven byte-by-byte data transfer ? arbitration-lost interrupt with automatic mode switching from master to slave ? calling address identification interrupt ? start and stop signal generation and detection ? repeated start signal generation and detection ? acknowledge bit generation and detection ? bus busy detection ? general call recognition kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 587
? 10-bit address extension ? support for system management bus (smbus) specification, version 2 ? programmable glitch input filter ? low power mode wakeup on slave address match ? range slave address support ? dma support 35.1.2 modes of operation the i2c module's operation in various low power modes is as follows: ? run mode: this is the basic mode of operation. to conserve power in this mode, disable the module. ? wait mode: the module continues to operate when the core is in wait mode and can provide a wakeup interrupt. ? stop mode: the module is inactive in stop mode for reduced power consumption, except that address matching is enabled in stop mode. the stop instruction does not affect the i2c module's register states. 35.1.3 block diagram the following figure is a functional block diagram of the i2c module. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 588 freescale semiconductor, inc.
interrupt write/read address scl sda module enable ctrl_reg data_mux addr_decode data_reg status_reg addr_reg freq_reg input sync clock control start stop arbitration control in/out data shift register address compare figure 35-1. i2c functional block diagram 35.2 i 2 c signal descriptions the signal properties of i 2 c are shown in the following table. table 35-1. i 2 c signal descriptions signal description i/o scl bidirectional serial clock line of the i 2 c system. i/o sda bidirectional serial data line of the i 2 c system. i/o memory map and register descriptions this section describes in detail all i2c registers accessible to the end user. 35.3 chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 589
i2c memory map absolute address (hex) register name width (in bits) access reset value section/ page 4006_6000 i2c address register 1 (i2c0_a1) 8 r/w 00h 35.3.1/590 4006_6001 i2c frequency divider register (i2c0_f) 8 r/w 00h 35.3.2/591 4006_6002 i2c control register 1 (i2c0_c1) 8 r/w 00h 35.3.3/592 4006_6003 i2c status register (i2c0_s) 8 r/w 80h 35.3.4/593 4006_6004 i2c data i/o register (i2c0_d) 8 r/w 00h 35.3.5/595 4006_6005 i2c control register 2 (i2c0_c2) 8 r/w 00h 35.3.6/596 4006_6006 i2c programmable input glitch filter register (i2c0_flt) 8 r/w 00h 35.3.7/597 4006_6007 i2c range address register (i2c0_ra) 8 r/w 00h 35.3.8/598 4006_6008 i2c smbus control and status register (i2c0_smb) 8 r/w 00h 35.3.9/599 4006_6009 i2c address register 2 (i2c0_a2) 8 r/w c2h 35.3.10/ 600 4006_600a i2c scl low timeout register high (i2c0_slth) 8 r/w 00h 35.3.11/ 601 4006_600b i2c scl low timeout register low (i2c0_sltl) 8 r/w 00h 35.3.12/ 601 35.3.1 i2c address register 1 (i2c x _a1) this register contains the slave address to be used by the i2c module. address: 4006_6000h base + 0h offset = 4006_6000h bit 7 6 5 4 3 2 1 0 read ad[7:1] 0 write reset 0 0 0 0 0 0 0 0 i2c x _a1 field descriptions field description 7C1 ad[7:1] address contains the primary slave address used by the i2c module when it is addressed as a slave. this field is used in the 7-bit address scheme and the lower seven bits in the 10-bit address scheme. 0 reserved this field is reserved. this read-only field is reserved and always has the value 0. memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 590 freescale semiconductor, inc.
35.3.2 i2c frequency divider register (i2c x _f) address: 4006_6000h base + 1h offset = 4006_6001h bit 7 6 5 4 3 2 1 0 read mult icr write reset 0 0 0 0 0 0 0 0 i2c x _f field descriptions field description 7C6 mult the mult bits define the multiplier factor mul. this factor is used along with the scl divider to generate the i2c baud rate. 00 mul = 1 01 mul = 2 10 mul = 4 11 reserved 5C0 icr clockrate prescales the bus clock for bit rate selection. this field and the mult field determine the i2c baud rate, the sda hold time, the scl start hold time, and the scl stop hold time. for a list of values corresponding to each icr setting, see i2c divider and hold values . the scl divider multiplied by multiplier factor (mul) determines the i2c baud rate. i2c baud rate = bus speed (hz)/(mul scl divider) the sda hold time is the delay from the falling edge of scl (i2c clock) to the changing of sda (i2c data). sda hold time = bus period (s) mul sda hold value the scl start hold time is the delay from the falling edge of sda (i2c data) while scl is high (start condition) to the falling edge of scl (i2c clock). scl start hold time = bus period (s) mul scl start hold value the scl stop hold time is the delay from the rising edge of scl (i2c clock) to the rising edge of sda (i2c data) while scl is high (stop condition). scl stop hold time = bus period (s) mul scl stop hold value for example, if the bus speed is 8 mhz, the following table shows the possible hold time values with different icr and mult selections to achieve an i 2 c baud rate of 100 kbps. mult icr hold times (s) sda scl start scl stop 2h 00h 3.500 3.000 5.500 1h 07h 2.500 4.000 5.250 1h 0bh 2.250 4.000 5.250 0h 14h 2.125 4.250 5.125 0h 18h 1.125 4.750 5.125 chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 591
35.3.3 i2c control register 1 (i2c x _c1) address: 4006_6000h base + 2h offset = 4006_6002h bit 7 6 5 4 3 2 1 0 read iicen iicie mst tx txak 0 wuen dmaen write rsta reset 0 0 0 0 0 0 0 0 i2c x _c1 field descriptions field description 7 iicen i2c enable enables i2c module operation. 0 disabled 1 enabled 6 iicie i2c interrupt enable enables i2c interrupt requests. 0 disabled 1 enabled 5 mst master mode select when the mst bit is changed from a 0 to a 1, a start signal is generated on the bus and master mode is selected. when this bit changes from a 1 to a 0, a stop signal is generated and the mode of operation changes from master to slave. 0 slave mode 1 master mode 4 tx transmit mode select selects the direction of master and slave transfers. in master mode this bit must be set according to the type of transfer required. therefore, for address cycles, this bit is always set. when addressed as a slave this bit must be set by software according to the srw bit in the status register. 0 receive 1 transmit 3 txak transmit acknowledge enable specifies the value driven onto the sda during data acknowledge cycles for both master and slave receivers. the value of the fack bit affects nack/ack generation. note: scl is held low until txak is written. 0 an acknowledge signal is sent to the bus on the following receiving byte (if fack is cleared) or the current receiving byte (if fack is set). 1 no acknowledge signal is sent to the bus on the following receiving data byte (if fack is cleared) or the current receiving data byte (if fack is set). table continues on the next page... memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 592 freescale semiconductor, inc.
i2c x _c1 field descriptions (continued) field description 2 rsta repeat start writing a one to this bit generates a repeated start condition provided it is the current master. this bit will always be read as zero. attempting a repeat at the wrong time results in loss of arbitration. 1 wuen wakeup enable the i2c module can wake the mcu from low power mode with no peripheral bus running when slave address matching occurs. 0 normal operation. no interrupt generated when address matching in low power mode. 1 enables the wakeup function in low power mode. 0 dmaen dma enable the dmaen bit enables or disables the dma function. 0 all dma signalling disabled. 1 dma transfer is enabled and the following conditions trigger the dma request: ? while fack = 0, a data byte is received, either address or data is transmitted. (ack/nack automatic) ? while fack = 0, the first byte received matches the a1 register or is general call address. if any address matching occurs, iaas and tcf are set. if the direction of transfer is known from master to slave, then it is not required to check the srw. with this assumption, dma can also be used in this case. in other cases, if the master reads data from the slave, then it is required to rewrite the c1 register operation. with this assumption, dma cannot be used. when fack = 1, an address or a data byte is transmitted. 35.3.4 i2c status register (i2c x _s) address: 4006_6000h base + 3h offset = 4006_6003h bit 7 6 5 4 3 2 1 0 read tcf iaas busy arbl ram srw iicif rxak write w1c w1c reset 1 0 0 0 0 0 0 0 i2c x _s field descriptions field description 7 tcf transfer complete flag this bit sets on the completion of a byte and acknowledge bit transfer. this bit is valid only during or immediately following a transfer to or from the i2c module. the tcf bit is cleared by reading the i2c data register in receive mode or by writing to the i2c data register in transmit mode. 0 transfer in progress 1 transfer complete table continues on the next page... chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 593
i2c x _s field descriptions (continued) field description 6 iaas addressed as a slave this bit is set by one of the following conditions: ? the calling address matches the programmed slave primary address in the a1 register or range address in the ra register (which must be set to a nonzero value). ? gcaen is set and a general call is received. ? siicaen is set and the calling address matches the second programmed slave address. ? alerten is set and an smbus alert response address is received ? rmen is set and an address is received that is within the range between the values of the a1 and ra registers. this bit sets before the ack bit. the cpu must check the srw bit and set tx/rx accordingly. writing the c1 register with any value clears this bit. 0 not addressed 1 addressed as a slave 5 busy bus busy indicates the status of the bus regardless of slave or master mode. this bit is set when a start signal is detected and cleared when a stop signal is detected. 0 bus is idle 1 bus is busy 4 arbl arbitration lost this bit is set by hardware when the arbitration procedure is lost. the arbl bit must be cleared by software, by writing a one to it. 0 standard bus operation. 1 loss of arbitration. 3 ram range address match this bit is set to 1 by any of the following conditions: ? any nonzero calling address is received that matches the address in the ra register. ? the rmen bit is set and the calling address is within the range of values of the a1 and ra registers. note: for the ram bit to be set to 1 correctly, c1[iicie] must be set to 1. writing the c1 register with any value clears this bit to 0. 0 not addressed 1 addressed as a slave 2 srw slave read/write when addressed as a slave, srw indicates the value of the r/ w command bit of the calling address sent to the master. 0 slave receive, master writing to slave 1 slave transmit, master reading from slave 1 iicif interrupt flag this bit sets when an interrupt is pending. this bit must be cleared by software by writing a 1 to it, such as in the interrupt routine. one of the following events can set this bit: table continues on the next page... memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 594 freescale semiconductor, inc.
i2c x _s field descriptions (continued) field description ? one byte transfer, including ack/nack bit, completes if fack is 0. an ack or nack is sent on the bus by writing 0 or 1 to txak after this bit is set in receive mode. ? one byte transfer, excluding ack/nack bit, completes if fack is 1. ? match of slave address to calling address including primary slave address, range slave address, alert response address, second slave address, or general call address. ? arbitration lost ? in smbus mode, any timeouts except scl and sda high timeouts ? i2c bus stop detection if the stopie bit in the input glitch filter register is 1 note: to clear the i2c bus stop detection interrupt: in the interrupt service routine, first clear the stopf bit in the input glitch filter register by writing 1 to it, and then clear the iicif bit. if this sequence is reversed, the iicif bit is asserted again. 0 no interrupt pending 1 interrupt pending 0 rxak receive acknowledge 0 acknowledge signal was received after the completion of one byte of data transmission on the bus 1 no acknowledge signal detected 35.3.5 i2c data i/o register (i2c x _d) address: 4006_6000h base + 4h offset = 4006_6004h bit 7 6 5 4 3 2 1 0 read data write reset 0 0 0 0 0 0 0 0 i2c x _d field descriptions field description 7C0 data data in master transmit mode, when data is written to this register, a data transfer is initiated. the most significant bit is sent first. in master receive mode, reading this register initiates receiving of the next byte of data. note: when making the transition out of master receive mode, switch the i2c mode before reading the data register to prevent an inadvertent initiation of a master receive data transfer. in slave mode, the same functions are available after an address match occurs. the c1[tx] bit must correctly reflect the desired direction of transfer in master and slave modes for the transmission to begin. for example, if the i2c module is configured for master transmit but a master receive is desired, reading the data register does not initiate the receive. reading the data register returns the last byte received while the i2c module is configured in master receive or slave receive mode. the data register does not reflect every byte that is transmitted on the i2c bus, and neither can software verify that a byte has been written to the data register correctly by reading it back. chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 595
i2c x _d field descriptions (continued) field description in master transmit mode, the first byte of data written to the data register following assertion of mst (start bit) or assertion of rsta (repeated start bit) is used for the address transfer and must consist of the calling address (in bits 7-1) concatenated with the required r/ w bit (in position bit 0). 35.3.6 i2c control register 2 (i2c x _c2) address: 4006_6000h base + 5h offset = 4006_6005h bit 7 6 5 4 3 2 1 0 read gcaen adext hdrs sbrc rmen ad[10:8] write reset 0 0 0 0 0 0 0 0 i2c x _c2 field descriptions field description 7 gcaen general call address enable enables general call address. 0 disabled 1 enabled 6 adext address extension controls the number of bits used for the slave address. 0 7-bit address scheme 1 10-bit address scheme 5 hdrs high drive select controls the drive capability of the i2c pads. 0 normal drive mode 1 high drive mode 4 sbrc slave baud rate control enables independent slave mode baud rate at maximum frequency, which forces clock stretching on scl in very fast i2c modes. to a slave, an example of a "very fast" mode is when the master transfers at 40 kbps but the slave can capture the master's data at only 10 kbps. 0 the slave baud rate follows the master baud rate and clock stretching may occur 1 slave baud rate is independent of the master baud rate 3 rmen range address matching enable this bit controls slave address matching for addresses between the values of the a1 and ra registers. when this bit is set, a slave address match occurs for any address greater than the value of the a1 register and less than or equal to the value of the ra register. table continues on the next page... memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 596 freescale semiconductor, inc.
i2c x _c2 field descriptions (continued) field description 0 range mode disabled. no address match occurs for an address within the range of values of the a1 and ra registers. 1 range mode enabled. address matching occurs when a slave receives an address within the range of values of the a1 and ra registers. 2C0 ad[10:8] slave address contains the upper three bits of the slave address in the 10-bit address scheme. this field is valid only while the adext bit is set. 35.3.7 i2c programmable input glitch filter register (i2c x _flt) address: 4006_6000h base + 6h offset = 4006_6006h bit 7 6 5 4 3 2 1 0 read shen stopf stopie flt write w1c reset 0 0 0 0 0 0 0 0 i2c x _flt field descriptions field description 7 shen stop hold enable set this bit to hold off entry to stop mode when any data transmission or reception is occurring. the following scenario explains the holdoff functionality: 1. the i2c module is configured for a basic transfer, and the shen bit is set to 1. 2. a transfer begins. 3. the mcu signals the i2c module to enter stop mode. 4. the byte currently being transferred, including both address and data, completes its transfer. 5. the i2c slave or master acknowledges that the in-transfer byte completed its transfer and acknowledges the request to enter stop mode. 6. after receiving the i2c module's acknowledgment of the request to enter stop mode, the mcu determines whether to shut off the i2c module's clock. if the shen bit is set to 1 and the i2c module is in an idle or disabled state when the mcu signals to enter stop mode, the module immediately acknowledges the request to enter stop mode. if shen is cleared to 0 and the overall data transmission or reception that was suspended by stop mode entry was incomplete: to resume the overall transmission or reception after the mcu exits stop mode, software must reinitialize the transfer by resending the address of the slave. if the i2c control register 1's iicie bit was set to 1 before the mcu entered stop mode, system software will receive the interrupt triggered by the i2c status register's tcf bit after the mcu wakes from the stop mode. 0 stop holdoff is disabled. the mcu's entry to stop mode is not gated. 1 stop holdoff is enabled. 6 stopf i2c bus stop detect flag table continues on the next page... chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 597
i2c x _flt field descriptions (continued) field description hardware sets this bit when the i2c bus's stop status is detected. the stopf bit must be cleared by writing 1 to it. 0 no stop happens on i2c bus 1 stop detected on i2c bus 5 stopie i2c bus stop interrupt enable this bit enables the interrupt for i2c bus stop detection. note: to clear the i2c bus stop detection interrupt: in the interrupt service routine, first clear the stopf bit by writing 1 to it, and then clear the iicif bit in the status register. if this sequence is reversed, the iicif bit is asserted again. 0 stop detection interrupt is disabled 1 stop detection interrupt is enabled 4C0 flt i2c programmable filter factor controls the width of the glitch, in terms of bus clock cycles, that the filter must absorb. for any glitch whose size is less than or equal to this width setting, the filter does not allow the glitch to pass. 00h no filter/bypass 01-1fh filter glitches up to width of n bus clock cycles, where n =1-31d 35.3.8 i2c range address register (i2c x _ra) address: 4006_6000h base + 7h offset = 4006_6007h bit 7 6 5 4 3 2 1 0 read rad 0 write reset 0 0 0 0 0 0 0 0 i2c x _ra field descriptions field description 7C1 rad range slave address this field contains the slave address to be used by the i2c module. the field is used in the 7-bit address scheme. any nonzero write enables this register. this register's use is similar to that of the a1 register, but in addition this register can be considered a maximum boundary in range matching mode. 0 reserved this field is reserved. this read-only field is reserved and always has the value 0. memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 598 freescale semiconductor, inc.
35.3.9 i2c smbus control and status register (i2c x _smb) note when the scl and sda signals are held high for a length of time greater than the high timeout period, the shtf1 flag sets. before reaching this threshold, while the system is detecting how long these signals are being held high, a master assumes that the bus is free. however, the shtf1 bit rises in the bus transmission process with the idle bus state. note when the tcksel bit is set, there is no need to monitor the shtf1 bit because the bus speed is too high to match the protocol of smbus. address: 4006_6000h base + 8h offset = 4006_6008h bit 7 6 5 4 3 2 1 0 read fack alerten siicaen tcksel sltf shtf1 shtf2 shtf2ie write w1c w1c reset 0 0 0 0 0 0 0 0 i2c x _smb field descriptions field description 7 fack fast nack/ack enable for smbus packet error checking, the cpu must be able to issue an ack or nack according to the result of receiving data byte. 0 an ack or nack is sent on the following receiving data byte 1 writing 0 to txak after receiving a data byte generates an ack. writing 1 to txak after receiving a data byte generates a nack. 6 alerten smbus alert response address enable enables or disables smbus alert response address matching. note: after the host responds to a device that used the alert response address, you must use software to put the device's address on the bus. the alert protocol is described in the smbus specification. 0 smbus alert response address matching is disabled 1 smbus alert response address matching is enabled 5 siicaen second i2c address enable enables or disables smbus device default address. 0 i2c address register 2 matching is disabled 1 i2c address register 2 matching is enabled table continues on the next page... chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 599
i2c x _smb field descriptions (continued) field description 4 tcksel timeout counter clock select selects the clock source of the timeout counter. 0 timeout counter counts at the frequency of the bus clock / 64 1 timeout counter counts at the frequency of the bus clock 3 sltf scl low timeout flag this bit is set when the slt register (consisting of the slth and sltl registers) is loaded with a non-zero value (lovalue) and an scl low timeout occurs. software clears this bit by writing a logic 1 to it. note: the low timeout function is disabled when the slt register's value is zero. 0 no low timeout occurs 1 low timeout occurs 2 shtf1 scl high timeout flag 1 this read-only bit sets when scl and sda are held high more than clock lovalue / 512, which indicates the bus is free. this bit is cleared automatically. 0 no scl high and sda high timeout occurs 1 scl high and sda high timeout occurs 1 shtf2 scl high timeout flag 2 this bit sets when scl is held high and sda is held low more than clock lovalue/512. software clears this bit by writing a 1 to it. 0 no scl high and sda low timeout occurs 1 scl high and sda low timeout occurs 0 shtf2ie shtf2 interrupt enable enables scl high and sda low timeout interrupt. 0 shtf2 interrupt is disabled 1 shtf2 interrupt is enabled 35.3.10 i2c address register 2 (i2c x _a2) address: 4006_6000h base + 9h offset = 4006_6009h bit 7 6 5 4 3 2 1 0 read sad 0 write reset 1 1 0 0 0 0 1 0 i2c x _a2 field descriptions field description 7C1 sad smbus address table continues on the next page... memory map and register descriptions kl04 sub-family reference manual, rev. 3.1, november 2012 600 freescale semiconductor, inc.
i2c x _a2 field descriptions (continued) field description contains the slave address used by the smbus. this field is used on the device default address or other related addresses. 0 reserved this field is reserved. this read-only field is reserved and always has the value 0. 35.3.11 i2c scl low timeout register high (i2c x _slth) address: 4006_6000h base + ah offset = 4006_600ah bit 7 6 5 4 3 2 1 0 read sslt[15:8] write reset 0 0 0 0 0 0 0 0 i2c x _slth field descriptions field description 7C0 sslt[15:8] most significant byte of scl low timeout value that determines the timeout period of scl low. 35.3.12 i2c scl low timeout register low (i2c x _sltl) address: 4006_6000h base + bh offset = 4006_600bh bit 7 6 5 4 3 2 1 0 read sslt[7:0] write reset 0 0 0 0 0 0 0 0 i2c x _sltl field descriptions field description 7C0 sslt[7:0] least significant byte of scl low timeout value that determines the timeout period of scl low. 35.4 functional description this section provides a comprehensive functional description of the i2c module. chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 601
35.4.1 i2c protocol the i2c bus system uses a serial data line (sda) and a serial clock line (scl) for data transfers. all devices connected to it must have open drain or open collector outputs. a logic and function is exercised on both lines with external pull-up resistors. the value of these resistors depends on the system. normally, a standard instance of communication is composed of four parts: 1. start signal 2. slave address transmission 3. data transfer 4. stop signal the stop signal should not be confused with the cpu stop instruction. the following figure illustrates i2c bus system communication. s c l s d a d 0 d a t a b y t e n e w c a l l i n g a d d r e s s x x w r i t e c a l l i n g a d d r e s s w r i t e w r i t e s d a c a l l i n g a d d r e s s r e a d / x x x d 7 d 6 d 5 d 4 d 3 d 2 d 1 a d 6 a d 5 a d 7 a d 4 l s b m s b 1 6 2 5 8 3 4 7 9 1 6 2 5 8 3 4 7 9 l s b m s b 1 6 2 5 8 3 4 7 9 l s b m s b 1 6 2 5 8 3 4 7 9 l s b m s b a d 6 r / w a d 3 a d 2 a d 1 a d 5 a d 7 a d 4 a d 6 r / w a d 3 a d 2 a d 1 a d 5 a d 7 a d 4 r e a d / r e a d / r / w a d 3 a d 2 a d 1 scl start signal ack bit no ack bit stop signal start signal ack bit repeated start signal no ack bit stop signal figure 35-26. i2c bus transmission signals 35.4.1.1 start signal the bus is free when no master device is engaging the bus (both scl and sda are high). when the bus is free, a master may initiate communication by sending a start signal. a start signal is defined as a high-to-low transition of sda while scl is high. this signal denotes the beginning of a new data transfereach data transfer might contain several bytes of dataand brings all slaves out of their idle states. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 602 freescale semiconductor, inc.
35.4.1.2 slave address transmission immediately after the start signal, the first byte of a data transfer is the slave address transmitted by the master. this address is a 7-bit calling address followed by an r/ w bit. the r/ w bit tells the slave the desired direction of data transfer. ? 1 = read transfer: the slave transmits data to the master ? 0 = write transfer: the master transmits data to the slave only the slave with a calling address that matches the one transmitted by the master responds by sending an acknowledge bit. the slave sends the acknowledge bit by pulling sda low at the ninth clock. no two slaves in the system can have the same address. if the i2c module is the master, it must not transmit an address that is equal to its own slave address. the i2c module cannot be master and slave at the same time. however, if arbitration is lost during an address cycle, the i2c module reverts to slave mode and operates correctly even if it is being addressed by another master. 35.4.1.3 data transfers when successful slave addressing is achieved, data transfer can proceed on a byte-by- byte basis in the direction specified by the r/ w bit sent by the calling master. all transfers that follow an address cycle are referred to as data transfers, even if they carry subaddress information for the slave device. each data byte is 8 bits long. data may be changed only while scl is low. data must be held stable while scl is high. there is one clock pulse on scl for each data bit, and the msb is transferred first. each data byte is followed by a ninth (acknowledge) bit, which is signaled from the receiving device by pulling sda low at the ninth clock. in summary, one complete data transfer needs nine clock pulses. if the slave receiver does not acknowledge the master in the ninth bit, the slave must leave sda high. the master interprets the failed acknowledgement as an unsuccessful data transfer. if the master receiver does not acknowledge the slave transmitter after a data byte transmission, the slave interprets it as an end to data transfer and releases the sda line. in the case of a failed acknowledgement by either the slave or master, the data transfer is aborted and the master does one of two things: chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 603
? relinquishes the bus by generating a stop signal. ? commences a new call by generating a repeated start signal. 35.4.1.4 stop signal the master can terminate the communication by generating a stop signal to free the bus. a stop signal is defined as a low-to-high transition of sda while scl is asserted. the master can generate a stop signal even if the slave has generated an acknowledgement, at which point the slave must release the bus. 35.4.1.5 repeated start signal the master may generate a start signal followed by a calling command without generating a stop signal first. this action is called a repeated start. the master uses a repeated start to communicate with another slave or with the same slave in a different mode (transmit/receive mode) without releasing the bus. 35.4.1.6 arbitration procedure the i2c bus is a true multimaster bus that allows more than one master to be connected on it. if two or more masters try to control the bus at the same time, a clock synchronization procedure determines the bus clock. the bus clock's low period is equal to the longest clock low period, and the high period is equal to the shortest one among the masters. the relative priority of the contending masters is determined by a data arbitration procedure. a bus master loses arbitration if it transmits logic level 1 while another master transmits logic level 0. the losing masters immediately switch to slave receive mode and stop driving sda output. in this case, the transition from master to slave mode does not generate a stop condition. meanwhile, hardware sets a status bit to indicate the loss of arbitration. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 604 freescale semiconductor, inc.
35.4.1.7 clock synchronization because wire and logic is performed on scl, a high-to-low transition on scl affects all devices connected on the bus. the devices start counting their low period and, after a device's clock has gone low, that device holds scl low until the clock reaches its high state. however, the change of low to high in this device clock might not change the state of scl if another device clock is still within its low period. therefore, the synchronized clock scl is held low by the device with the longest low period. devices with shorter low periods enter a high wait state during this time; see the following diagram. when all applicable devices have counted off their low period, the synchronized clock scl is released and pulled high. afterward there is no difference between the device clocks and the state of scl, and all devices start counting their high periods. the first device to complete its high period pulls scl low again. s c l 2 s t a r t c o u n t i n g h i g h p e r i o d i n t e r n a l c o u n t e r r e s e t s c l 1 s c l d e l a y figure 35-27. i2c clock synchronization 35.4.1.8 handshaking the clock synchronization mechanism can be used as a handshake in data transfers. a slave device may hold scl low after completing a single byte transfer (9 bits). in this case, it halts the bus clock and forces the master clock into wait states until the slave releases scl. 35.4.1.9 clock stretching the clock synchronization mechanism can be used by slaves to slow down the bit rate of a transfer. after the master drives scl low, a slave can drive scl low for the required period and then release it. if the slave's scl low period is greater than the master's scl chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 605
low period, the resulting scl bus signal's low period is stretched. in other words, the scl bus signal's low period is increased to be the same length as the slave's scl low period. 35.4.1.10 i2c divider and hold values note for some cases on some devices, the scl divider value may vary by +/-2 or +/-4 when icrs value ranges from 00h to 0fh. these potentially varying scl divider values are highlighted in the following table. for the actual scl divider values for your device, see the chip-specific details about the i2c module. table 35-28. i2c divider and hold values icr (hex) scl divider sda hold value scl hold (start) value scl hold (stop) value icr (hex) scl divider (clocks) sda hold (clocks) scl hold (start) value scl hold (stop) value 00 20 7 6 11 20 160 17 78 81 01 22 7 7 12 21 192 17 94 97 02 24 8 8 13 22 224 33 110 113 03 26 8 9 14 23 256 33 126 129 04 28 9 10 15 24 288 49 142 145 05 30 9 11 16 25 320 49 158 161 06 34 10 13 18 26 384 65 190 193 07 40 10 16 21 27 480 65 238 241 08 28 7 10 15 28 320 33 158 161 09 32 7 12 17 29 384 33 190 193 0a 36 9 14 19 2a 448 65 222 225 0b 40 9 16 21 2b 512 65 254 257 0c 44 11 18 23 2c 576 97 286 289 0d 48 11 20 25 2d 640 97 318 321 0e 56 13 24 29 2e 768 129 382 385 0f 68 13 30 35 2f 960 129 478 481 10 48 9 18 25 30 640 65 318 321 11 56 9 22 29 31 768 65 382 385 12 64 13 26 33 32 896 129 446 449 13 72 13 30 37 33 1024 129 510 513 14 80 17 34 41 34 1152 193 574 577 15 88 17 38 45 35 1280 193 638 641 16 104 21 46 53 36 1536 257 766 769 17 128 21 58 65 37 1920 257 958 961 table continues on the next page... functional description kl04 sub-family reference manual, rev. 3.1, november 2012 606 freescale semiconductor, inc.
table 35-28. i2c divider and hold values (continued) icr (hex) scl divider sda hold value scl hold (start) value scl hold (stop) value icr (hex) scl divider (clocks) sda hold (clocks) scl hold (start) value scl hold (stop) value 18 80 9 38 41 38 1280 129 638 641 19 96 9 46 49 39 1536 129 766 769 1a 112 17 54 57 3a 1792 257 894 897 1b 128 17 62 65 3b 2048 257 1022 1025 1c 144 25 70 73 3c 2304 385 1150 1153 1d 160 25 78 81 3d 2560 385 1278 1281 1e 192 33 94 97 3e 3072 513 1534 1537 1f 240 33 118 121 3f 3840 513 1918 1921 35.4.2 10-bit address for 10-bit addressing, 0x11110 is used for the first 5 bits of the first address byte. various combinations of read/write formats are possible within a transfer that includes 10-bit addressing. 35.4.2.1 master-transmitter addresses a slave-receiver the transfer direction is not changed. when a 10-bit address follows a start condition, each slave compares the first 7 bits of the first byte of the slave address (11110xx) with its own address and tests whether the eighth bit (r/ w direction bit) is 0. it is possible that more than one device finds a match and generates an acknowledge (a1). each slave that finds a match compares the 8 bits of the second byte of the slave address with its own address, but only one slave finds a match and generates an acknowledge (a2). the matching slave remains addressed by the master until it receives a stop condition (p) or a repeated start condition (sr) followed by a different slave address. table 35-29. master-transmitter addresses slave-receiver with a 10-bit address s slave address first 7 bits 11110 + ad10 + ad9 r/ w 0 a1 slave address second byte ad[8:1] a2 data a ... data a/a p chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 607
after the master-transmitter has sent the first byte of the 10-bit address, the slave-receiver sees an i2c interrupt. user software must ensure that for this interrupt, the contents of the data register are ignored and not treated as valid data. 35.4.2.2 master-receiver addresses a slave-transmitter the transfer direction is changed after the second r/ w bit. up to and including acknowledge bit a2, the procedure is the same as that described for a master-transmitter addressing a slave-receiver. after the repeated start condition (sr), a matching slave remembers that it was addressed before. this slave then checks whether the first seven bits of the first byte of the slave address following sr are the same as they were after the start condition (s), and it tests whether the eighth (r/ w) bit is 1. if there is a match, the slave considers that it has been addressed as a transmitter and generates acknowledge a3. the slave-transmitter remains addressed until it receives a stop condition (p) or a repeated start condition (sr) followed by a different slave address. after a repeated start condition (sr), all other slave devices also compare the first seven bits of the first byte of the slave address with their own addresses and test the eighth (r/ w) bit. however, none of them are addressed because r/ w = 1 (for 10-bit devices), or the 11110xx slave address (for 7-bit devices) does not match. table 35-30. master-receiver addresses a slave-transmitter with a 10-bit address s slave address first 7 bits 11110 + ad10 + ad9 r/ w 0 a1 slave address second byte ad[8:1] a2 sr slave address first 7 bits 11110 + ad10 + ad9 r/ w 1 a3 data a ... data a p after the master-receiver has sent the first byte of the 10-bit address, the slave-transmitter sees an i2c interrupt. user software must ensure that for this interrupt, the contents of the data register are ignored and not treated as valid data. 35.4.3 address matching all received addresses can be requested in 7-bit or 10-bit address format. ? ad[7:1] in address register 1, which contains the i2c primary slave address, always participates in the address matching process. it provides a 7-bit address. ? if the adext bit is set, ad[10:8] in control register 2 participates in the address matching process. it extends the i2c primary slave address to a 10-bit address. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 608 freescale semiconductor, inc.
additional conditions that affect address matching include: ? if the gcaen bit is set, general call participates the address matching process. ? if the alerten bit is set, alert response participates the address matching process. ? if the siicaen bit is set, address register 2 participates in the address matching process. ? if the range address register is programmed to a nonzero value, the range address itself participates in the address matching process. ? if the rmen bit is set, any address within the range of values of address register 1 and the range address register participates in the address matching process. the range address register must be programmed to a value greater than the value of address register 1. when the i2c module responds to one of these addresses, it acts as a slave-receiver and the iaas bit is set after the address cycle. software must read the data register after the first byte transfer to determine that the address is matched. 35.4.4 system management bus specification smbus provides a control bus for system and power management related tasks. a system can use smbus to pass messages to and from devices instead of tripping individual control lines. removing the individual control lines reduces pin count. accepting messages ensures future expandability. with the system management bus, a device can provide manufacturer information, tell the system what its model/part number is, save its state for a suspend event, report different types of errors, accept control parameters, and return its status. 35.4.4.1 timeouts the t timeout,min parameter allows a master or slave to conclude that a defective device is holding the clock low indefinitely or a master is intentionally trying to drive devices off the bus. the slave device must release the bus (stop driving the bus and let scl and sda float high) when it detects any single clock held low longer than t timeout,min . devices that have detected this condition must reset their communication and be able to receive a new start condition within the timeframe of t timeout,max . smbus defines a clock low timeout, t timeout , of 35 ms, specifies t low:sext as the cumulative clock low extend time for a slave device, and specifies t low:mext as the cumulative clock low extend time for a master device. chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 609
35.4.4.1.1 scl low timeout if the scl line is held low by a slave device on the bus, no further communication is possible. furthermore, the master cannot force the scl line high to correct the error condition. to solve this problem, the smbus protocol specifies that devices participating in a transfer must detect any clock cycle held low longer than a timeout value condition. devices that have detected the timeout condition must reset the communication. when the i2c module is an active master, if it detects that smbclk low has exceeded the value of t timeout,min , it must generate a stop condition within or after the current data byte in the transfer process. when the i2c module is a slave, if it detects the t timeout,min condition, it resets its communication and is then able to receive a new start condition. 35.4.4.1.2 scl high timeout when the i2c module has determined that the smbclk and smbdat signals have been high for at least t high:max , it assumes that the bus is idle. a high timeout occurs after a start condition appears on the bus but before a stop condition appears on the bus. any master detecting this scenario can assume the bus is free when either of the following occurs: ? shtf1 rises. ? the busy bit is high and shtf1 is high. when the smbdat signal is low and the smbclk signal is high for a period of time, another kind of timeout occurs. the time period must be defined in software. shtf2 is used as the flag when the time limit is reached. this flag is also an interrupt resource, so it triggers iicif. 35.4.4.1.3 csmbclk timeout mext and csmbclk timeout sext the following figure illustrates the definition of the timeout intervals t low:sext and t low:mext . when in master mode, the i2c module must not cumulatively extend its clock cycles for a period greater than t low:mext within a byte, where each byte is defined as start-to-ack, ack-to-ack, or ack-to-stop. when csmbclk timeout mext occurs, smbus mext rises and also triggers the sltf. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 610 freescale semiconductor, inc.
start low:sext t stop low:mext t clkack low:mext t clkack low:mext t scl sda figure 35-28. timeout measurement intervals a master is allowed to abort the transaction in progress to any slave that violates the t low:sext or t timeout,min specifications. to abort the transaction, the master issues a stop condition at the conclusion of the byte transfer in progress. when a slave, the i2c module must not cumulatively extend its clock cycles for a period greater than t low:sext during any message from the initial start to the stop. when csmbclk timeout sext occurs, sext rises and also triggers sltf. note csmbclk timeout sext and csmbclk timeout mext are optional functions that are implemented in the second step. 35.4.4.2 fast ack and nack to improve reliability and communication robustness, implementation of packet error checking (pec) by smbus devices is optional for smbus devices but required for devices participating in and only during the address resolution protocol (arp) process. the pec is a crc-8 error checking byte, calculated on all the message bytes. the pec is appended to the message by the device that supplied the last data byte. if the pec is present but not correct, a nack is issued by the receiver. otherwise an ack is issued. to calculate the crc-8 by software, this module can hold the scl line low after receiving the eighth scl (8th bit) if this byte is a data byte. so software can determine whether an ack or nack should be sent to the bus by setting or clearing the txak bit if the fack (fast ack/nack enable) bit is enabled. smbus requires a device always to acknowledge its own address, as a mechanism to detect the presence of a removable device (such as a battery or docking station) on the bus. in addition to indicating a slave device busy condition, smbus uses the nack mechanism to indicate the reception of an invalid command or invalid data. because such a condition may occur on the last byte of the transfer, smbus devices are required to chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 611
have the ability to generate the not acknowledge after the transfer of each byte and before the completion of the transaction. this requirement is important because smbus does not provide any other resend signaling. this difference in the use of the nack signaling has implications on the specific implementation of the smbus port, especially in devices that handle critical system data such as the smbus host and the sbs components. note in the last byte of master receive slave transmit mode, the master must send a nack to the bus, so fack must be switched off before the last byte transmits. 35.4.5 resets the i2c module is disabled after a reset. the i2c module cannot cause a core reset. 35.4.6 interrupts the i2c module generates an interrupt when any of the events in the following table occur, provided that the iicie bit is set. the interrupt is driven by the iicif bit (of the i2c status register) and masked with the iicie bit (of the i2c control register 1). the iicif bit must be cleared (by software) by writing 1 to it in the interrupt routine. the smbus timeouts interrupt is driven by sltf and masked with the iicie bit. the sltf bit must be cleared by software by writing 1 to it in the interrupt routine. you can determine the interrupt type by reading the status register. note in master receive mode, the fack bit must be set to zero before the last byte transfer. table 35-31. interrupt summary interrupt source status flag local enable complete 1-byte transfer tcf iicif iicie match of received calling address iaas iicif iicie arbitration lost arbl iicif iicie i 2 c bus stop detection stopf iicif iicie & stopie smbus scl low timeout sltf iicif iicie smbus scl high sda low timeout shtf2 iicif iicie & shtf2ie wakeup from stop or wait mode iaas iicif iicie & wuen functional description kl04 sub-family reference manual, rev. 3.1, november 2012 612 freescale semiconductor, inc.
35.4.6.1 byte transfer interrupt the transfer complete flag (tcf) bit is set at the falling edge of the ninth clock to indicate the completion of a byte and acknowledgement transfer. when fack is enabled, tcf is then set at the falling edge of eighth clock to indicate the completion of byte. 35.4.6.2 address detect interrupt when the calling address matches the programmed slave address (i2c address register) or when the gcaen bit is set and a general call is received, the iaas bit in the status register is set. the cpu is interrupted, provided the iicie bit is set. the cpu must check the srw bit and set its tx mode accordingly. 35.4.6.3 stop detect interrupt when the stop status is detected on the i 2 c bus, the stopf bit is set to 1. the cpu is interrupted, provided the iicie and stopie bits are both set to 1. 35.4.6.4 exit from low-power/stop modes the slave receive input detect circuit and address matching feature are still active on low power modes (wait and stop). an asynchronous input matching slave address or general call address brings the cpu out of low power/stop mode if the interrupt is not masked. therefore, tcf and iaas both can trigger this interrupt. 35.4.6.5 arbitration lost interrupt the i2c is a true multimaster bus that allows more than one master to be connected on it. if two or more masters try to control the bus at the same time, the relative priority of the contending masters is determined by a data arbitration procedure. the i2c module asserts the arbitration-lost interrupt when it loses the data arbitration process and the arbl bit in the status register is set. arbitration is lost in the following circumstances: 1. sda is sampled as low when the master drives high during an address or data transmit cycle. chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 613
2. sda is sampled as low when the master drives high during the acknowledge bit of a data receive cycle. 3. a start cycle is attempted when the bus is busy. 4. a repeated start cycle is requested in slave mode. 5. a stop condition is detected when the master did not request it. the arbl bit must be cleared (by software) by writing 1 to it. 35.4.6.6 timeout interrupt in smbus when the iicie bit is set, the i2c module asserts a timeout interrupt (outputs sltf and shtf2) upon detection of any of the mentioned timeout conditions, with one exception. the scl high and sda high timeout mechanism must not be used to influence the timeout interrupt output, because this timeout indicates an idle condition on the bus. shtf1 rises when it matches the scl high and sda high timeout and falls automatically just to indicate the bus status. the shtf2's timeout period is the same as that of shtf1, which is short compared to that of sltf, so another control bit, shtf2ie, is added to enable or disable it. 35.4.7 programmable input glitch filter an i2c glitch filter has been added outside legacy i2c modules but within the i2c package. this filter can absorb glitches on the i2c clock and data lines for the i2c module. the width of the glitch to absorb can be specified in terms of the number of (half) bus clock cycles. a single programmable input glitch filter control register is provided. effectively, any down-up-down or up-down-up transition on the data line that occurs within the number of clock cycles programmed in this register is ignored by the i2c module. the programmer must specify the size of the glitch (in terms of bus clock cycles) for the filter to absorb and not pass. scl, sda external signals dff noise suppress circuits scl, sda internal signals dff dff dff figure 35-29. programmable input glitch filter diagram functional description kl04 sub-family reference manual, rev. 3.1, november 2012 614 freescale semiconductor, inc.
35.4.8 address matching wakeup when a primary, range, or general call address match occurs when the i2c module is in slave receive mode, the mcu wakes from a low power mode with no peripheral bus running. data sent on the bus that is the same as a target device address might also wake the target mcu. after the address matching iaas bit is set, an interrupt is sent at the end of address matching to wake the core. the iaas bit must be cleared after the clock recovery. note after the system recovers and is in run mode, restart the i2c module if it is needed to transfer packets. the scl line is not held low until the i2c module resets after address matching. the main purpose of this feature is to wake the mcu from a low power mode where no peripheral bus is running. when the mcu is in such a mode: addressing as a slave, slave read/write, and sending an acknowledge bit are not fully supported. to avoid i2c transfer problems resulting from this situation, firmware should prevent the mcu execution of a stop instruction when the i2c module is in the middle of a transfer unless the stop mode holdoff feature is used during this period (set flt[shen] to 1). 35.4.9 dma support if the dmaen bit is cleared and the iicie bit is set, an interrupt condition generates an interrupt request. if the dmaen bit is set and the iicie bit is set, an interrupt condition generates a dma request instead. dma requests are generated by the transfer complete flag (tcf). if the dmaen bit is set, the only arbitration lost is to another i2c module (error), and scl low timeouts (error) generate cpu interrupts. all other events initiate a dma transfer. note before the last byte of master receive mode, txak must be set to send a nack after the last bytes transfer. therefore, the dma must be disabled before the last bytes transfer. chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 615
note in 10-bit address mode transmission, the addresses to send occupy 2-3 bytes. during this transfer period, the dma must be disabled because the c1 register is written to send a repeat start or to change the transfer direction. 35.5 initialization/application information module initialization (slave) 1. write: control register 2 ? to enable or disable general call ? to select 10-bit or 7-bit addressing mode 2. write: address register 1 to set the slave address 3. write: control register 1 to enable the i2c module and interrupts 4. initialize ram variables (iicen = 1 and iicie = 1) for transmit data 5. initialize ram variables used to achieve the routine shown in the following figure module initialization (master) 1. write: frequency divider register to set the i2c baud rate (see example in description of icr ) 2. write: control register 1 to enable the i2c module and interrupts 3. initialize ram variables (iicen = 1 and iicie = 1) for transmit data 4. initialize ram variables used to achieve the routine shown in the following figure 5. write: control register 1 to enable tx 6. write: control register 1 to enable mst (master mode) 7. write: data register with the address of the target slave (the lsb of this byte determines whether the communication is master receive or transmit) the routine shown in the following figure encompasses both master and slave i2c operations. for slave operation, an incoming i2c message that contains the proper address begins i2c communication. for master operation, communication must be initiated by writing the data register. initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 616 freescale semiconductor, inc.
clear iicif master mode? tx/rx? arbitration lost? iiaas=1? tx/rx? ack from receiver? srw=1? iiaas=1? clear arbl 2nd to last byte to be read? last byte to be read? rxak=0? last byte transmitted? end of address cycle (master rx)? write next byte to data reg set txack generate stop signal (mst=0) write data to data reg set tx mode transmit next byte read data from data reg and store rti switch to rx mode set rx mode switch to rx mode dummy read from data reg generate stop signal (mst=0) read data from data reg and store dummy read from data reg dummy read from data reg n y n n n n n n y y y y y (read) n (write) n y rx tx rx tx y n address transfer see note 1 data transfer see note 2 n y y y notes: 1. if general call is enabled, check to determine if the received address is a general call address (0x00). if the received address is a general call address, the general call must be handled by user software. 2. when 10-bit addressing addresses a slave, the slave sees an interrupt following the first byte of the extended address. ensure that for this interrupt, the contents of the data register are ignored and not treated as a valid data transfer. figure 35-30. typical i2c interrupt routine chapter 35 inter-integrated circuit (i2c) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 617
master mode? tx/rx? arbitration lost? iaas=1? tx/rx? ack from receiver? srw=1? iaas=1? clear arbl 2nd to last byte to be read? last byte to be read? rxak=0? last byte transmitted? end of address cycle (master rx)? write next byte to data reg generate stop signal (mst=0) set txak to proper value clear iicif delay (note 2) delay (note 2) read data from data reg and soft crc transmit next byte rti switch to rx mode switch to rx mode dummy read from data reg generate stop signal (mst=0) read data from data reg and store read data from data reg and store dummy read from data reg n y n n n n n n y y y y y (read) n (write) n y rx tx rx tx y n address transfer see note 1 n y y y sltf or shtf2=1? n y clear iicif fack=1? n y see typical i2c interrupt routine flow chart set txak to proper value clear iicif delay (note 2) set tx mode write data to data reg clear iicif notes: 1. if general call or siicaen is enabled, check to determine if the received address is a general call address (0x00) or an smbus device default address. in either case, they must be handled by user software. 2. in receive mode, one bit time delay may be needed before the first and second data reading. clear iicif delay (note 2) read data from data reg and soft crc set txak to proper value clear iicif delay (note 2) delay (note 2) read data from data reg and soft crc set txack=1 clear fack=0 delay (note 2) read data and soft crc set txak to proper value delay (note 2) figure 35-31. typical i2c smbus interrupt routine initialization/application information kl04 sub-family reference manual, rev. 3.1, november 2012 618 freescale semiconductor, inc.
chapter 36 universal asynchronous receiver/transmitter (uart0) 36.1 introduction 36.1.1 features features of the uart module include: ? full-duplex, standard non-return-to-zero (nrz) format ? double-buffered transmitter and receiver with separate enables ? programmable baud rates (13-bit modulo divider) ? transmit and receive baud rate can operate asynchronous to the bus clock: ? baud rate can be configured independently of the bus clock frequency ? supports operation in stop modes ? configurable receiver buad rate oversampling ratio from 4x to 32x ? interrupt, dma or polled operation: ? transmit data register empty and transmission complete ? receive data register full ? receive overrun, parity error, framing error, and noise error ? idle receiver detect ? active edge on receive pin ? break detect supporting lin ? hardware parity generation and checking ? programmable 8-bit, 9-bit or 10-bit character length ? programmable 1-bit or 2-bit stop bits ? receiver wakeup by idle-line, address-mark or address match ? optional 13-bit break character generation / 11-bit break character detection ? selectable transmitter output and receiver input polarity kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 619
36.1.2 modes of operation 36.1.2.1 stop mode the uart will remain functional during stop mode, provided the asynchronous transmit and receive clock remains enabled. the uart can generate an interrupt or dma request to cause a wakeup from stop mode. 36.1.2.2 wait mode the uart can be configured to stop in wait modes, when the dozeen bit is set. the transmitter and receiver will finish transmitting/receiving the current word. 36.1.2.3 debug mode the uart remains functional in debug mode. 36.1.3 block diagram the following figure shows the transmitter portion of the uart. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 620 freescale semiconductor, inc.
h 8 7 6 5 4 3 2 1 0 l uart_d C tx buffer (write-only) internal bus stop 11-bit transmit shift register start shift direction lsb ? parity generation transmit control shift enable preamble (all 1s) break (all 0s) uart controls txd txd direction to txd pin logic loop control to receive data in to txd pin tx interrupt request loops rsrc tie tc tdre m pt pe tcie te sbk t8 txdir load from uartx_d txinv brk13 asynch module clock baud divider osr divider figure 36-1. uart transmitter block diagram the following figure shows the receiver portion of the uart. chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 621
m pe pt re variable 12-bit receive stop start receive wakeup data buffer internal bus sbr12:0 baudrate clock raf logic shift direction active edge detect lbkde msbf generator shift register m10 rxinv irq / dma logic dma requests irq requests parity logic control rxd rxd loops rsrc from transmitter receiver source control module asynch figure 36-2. uart receiver block diagram 36.2 register definition the uart includes registers to control baud rate, select uart options, report uart status, and for transmit/receive data. accesses to address outside the valid memory map will generate a bus error. uart memory map absolute address (hex) register name width (in bits) access reset value section/ page 4006_a000 uart baud rate register high (uart0_bdh) 8 r/w 00h 36.2.1/623 4006_a001 uart baud rate register low (uart0_bdl) 8 r/w 04h 36.2.2/624 4006_a002 uart control register 1 (uart0_c1) 8 r/w 00h 36.2.3/624 4006_a003 uart control register 2 (uart0_c2) 8 r/w 00h 36.2.4/626 4006_a004 uart status register 1 (uart0_s1) 8 r/w c0h 36.2.5/627 4006_a005 uart status register 2 (uart0_s2) 8 r/w 00h 36.2.6/629 4006_a006 uart control register 3 (uart0_c3) 8 r/w 00h 36.2.7/631 4006_a007 uart data register (uart0_d) 8 r/w 00h 36.2.8/632 4006_a008 uart match address registers 1 (uart0_ma1) 8 r/w 00h 36.2.9/633 table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 622 freescale semiconductor, inc.
uart memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page 4006_a009 uart match address registers 2 (uart0_ma2) 8 r/w 00h 36.2.10/ 634 4006_a00a uart control register 4 (uart0_c4) 8 r/w 0fh 36.2.11/ 634 4006_a00b uart control register 5 (uart0_c5) 8 r/w 00h 36.2.12/ 635 36.2.1 uart baud rate register high (uart x _bdh) this register, along with uart _bdl, controls the prescale divisor for uart baud rate generation. the 13-bit baud rate setting [sbr12:sbr0] should only be updated when the transmitter and receiver are both disabled. address: 4006_a000h base + 0h offset = 4006_a000h bit 7 6 5 4 3 2 1 0 read lbkdie rxedgie sbns sbr write reset 0 0 0 0 0 0 0 0 uart x _bdh field descriptions field description 7 lbkdie lin break detect interrupt enable (for lbkdif) 0 hardware interrupts from uart _s2[lbkdif] disabled (use polling). 1 hardware interrupt requested when uart _s2[lbkdif] flag is 1. 6 rxedgie rx input active edge interrupt enable (for rxedgif) 0 hardware interrupts from uart _s2[rxedgif] disabled (use polling). 1 hardware interrupt requested when uart _s2[rxedgif] flag is 1. 5 sbns stop bit number select sbns determines whether data characters are one or two stop bits. this bit should only be changed when the transmitter and receiver are both disabled. 0 one stop bit. 1 two stop bit. 4C0 sbr baud rate modulo divisor. the 13 bits in sbr[12:0] are referred to collectively as br, and they set the modulo divide rate for the baud rate generator. when br is 1 - 8191, the baud rate equals baud clock / ((osr+1) br). chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 623
36.2.2 uart baud rate register low (uart x _bdl) this register, along with uart _bdh, control the prescale divisor for uart baud rate generation. the 13-bit baud rate setting [sbr12:sbr0] can only be updated when the transmitter and receiver are both disabled. uart _bdl is reset to a non-zero value, so after reset the baud rate generator remains disabled until the first time the receiver or transmitter is enabled; that is, uart _c2[re] or uart _c2[te] bits are written to 1. address: 4006_a000h base + 1h offset = 4006_a001h bit 7 6 5 4 3 2 1 0 read sbr write reset 0 0 0 0 0 1 0 0 uart x _bdl field descriptions field description 7C0 sbr baud rate modulo divisor these 13 bits in sbr[12:0] are referred to collectively as br. they set the modulo divide rate for the baud rate generator. when br is 1 - 8191, the baud rate equals baud clock/((osr+1) br). 36.2.3 uart control register 1 (uart x _c1) this read/write register controls various optional features of the uart system. this register should only be altered when the transmitter and receiver are both disabled. address: 4006_a000h base + 2h offset = 4006_a002h bit 7 6 5 4 3 2 1 0 read loops dozeen rsrc m wake ilt pe pt write reset 0 0 0 0 0 0 0 0 uart x _c1 field descriptions field description 7 loops loop mode select selects between loop back modes and normal 2-pin full-duplex modes. when loops is set, the transmitter output is internally connected to the receiver input. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 624 freescale semiconductor, inc.
uart x _c1 field descriptions (continued) field description 0 normal operation - uart _rx and uart _tx use separate pins. 1 loop mode or single-wire mode where transmitter outputs are internally connected to receiver input. (see rsrc bit.) uart _rx pin is not used by uart . 6 dozeen doze enable 0 uart is enabled in wait mode. 1 uart is disabled in wait mode. 5 rsrc receiver source select this bit has no meaning or effect unless the loops bit is set to 1. when loops is set, the receiver input is internally connected to the uart _tx pin and rsrc determines whether this connection is also connected to the transmitter output. 0 provided loops is set, rsrc is cleared, selects internal loop back mode and the uart does not use the uart _rx pins. 1 single-wire uart mode where the uart _tx pin is connected to the transmitter output and receiver input. 4 m 9-bit or 8-bit mode select 0 receiver and transmitter use 8-bit data characters. 1 receiver and transmitter use 9-bit data characters. 3 wake receiver wakeup method select 0 idle-line wakeup. 1 address-mark wakeup. 2 ilt idle line type select setting this bit to 1 ensures that the stop bits and logic 1 bits at the end of a character do not count toward the 10 to 13 bit times of logic high level needed by the idle line detection logic. 0 idle character bit count starts after start bit. 1 idle character bit count starts after stop bit. 1 pe parity enable enables hardware parity generation and checking. when parity is enabled, the bit immediately before the stop bit is treated as the parity bit. 0 no hardware parity generation or checking. 1 parity enabled. 0 pt parity type provided parity is enabled (pe = 1), this bit selects even or odd parity. odd parity means the total number of 1s in the data character, including the parity bit, is odd. even parity means the total number of 1s in the data character, including the parity bit, is even. 0 even parity. 1 odd parity. chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 625
36.2.4 uart control register 2 (uart x _c2) this register can be read or written at any time. address: 4006_a000h base + 3h offset = 4006_a003h bit 7 6 5 4 3 2 1 0 read tie tcie rie ilie te re rwu sbk write reset 0 0 0 0 0 0 0 0 uart x _c2 field descriptions field description 7 tie transmit interrupt enable for tdre 0 hardware interrupts from tdre disabled; use polling. 1 hardware interrupt requested when tdre flag is 1. 6 tcie transmission complete interrupt enable for tc 0 hardware interrupts from tc disabled; use polling. 1 hardware interrupt requested when tc flag is 1. 5 rie receiver interrupt enable for rdrf 0 hardware interrupts from rdrf disabled; use polling. 1 hardware interrupt requested when rdrf flag is 1. 4 ilie idle line interrupt enable for idle 0 hardware interrupts from idle disabled; use polling. 1 hardware interrupt requested when idle flag is 1. 3 te transmitter enable te must be 1 to use the uart transmitter. when te is set, the uart forces the uart _tx pin to act as an output for the uart system. when the uart is configured for single-wire operation (loops = rsrc = 1), txdir controls the direction of traffic on the single uart communication line ( uart _tx pin). te can also queue an idle character by clearing te then setting te while a transmission is in progress. when te is written to 0, the transmitter keeps control of the port uart _tx pin until any data, queued idle, or queued break character finishes transmitting before allowing the pin to tristate. 0 transmitter disabled. 1 transmitter enabled. 2 re receiver enable when the uart receiver is off or loops is set, the uart _rx pin is not used by the uart . when re is written to 0, the receiver finishes receiving the current character (if any). 0 receiver disabled. 1 receiver enabled. 1 rwu receiver wakeup control table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 626 freescale semiconductor, inc.
uart x _c2 field descriptions (continued) field description this bit can be written to 1 to place the uart receiver in a standby state where it waits for automatic hardware detection of a selected wakeup condition. the wakeup condition is an idle line between messages, wake = 0, idle-line wakeup, or a logic 1 in the most significant data bit in a character, wake = 1, address-mark wakeup. application software sets rwu and, normally, a selected hardware condition automatically clears rwu. 0 normal uart receiver operation. 1 uart receiver in standby waiting for wakeup condition. 0 sbk send break writing a 1 and then a 0 to sbk queues a break character in the transmit data stream. additional break characters of 10 to 13, or 13 to 16 if brk13 = 1, bit times of logic 0 are queued as long as sbk is set. depending on the timing of the set and clear of sbk relative to the information currently being transmitted, a second break character may be queued before software clears sbk. 0 normal transmitter operation. 1 queue break character(s) to be sent. 36.2.5 uart status register 1 (uart x _s1) address: 4006_a000h base + 4h offset = 4006_a004h bit 7 6 5 4 3 2 1 0 read tdre tc rdrf idle or nf fe pf write w1c w1c w1c w1c w1c reset 1 1 0 0 0 0 0 0 uart x _s1 field descriptions field description 7 tdre transmit data register empty flag tdre is set out of reset and whenever there is room to write data to the transmit data buffer. to clear tdre, write to the uart data register ( uart _d). 0 transmit data buffer full. 1 transmit data buffer empty. 6 tc transmission complete flag tc is set out of reset and when tdre is set and no data, preamble, or break character is being transmitted. tc is cleared automatically by one of the following: ? write to the uart data register ( uart _d) to transmit new data ? queue a preamble by changing te from 0 to 1 ? queue a break character by writing 1 to uart _c2[sbk] 0 transmitter active (sending data, a preamble, or a break). 1 transmitter idle (transmission activity complete). table continues on the next page... chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 627
uart x _s1 field descriptions (continued) field description 5 rdrf receive data register full flag rdrf becomes set whenever the receive data buffer is full. to clear rdrf, read the uart data register ( uart _d). 0 receive data buffer empty. 1 receive data buffer full. 4 idle idle line flag idle is set when the uart receive line becomes idle for a full character time after a period of activity. when ilt is cleared, the receiver starts counting idle bit times after the start bit. if the receive character is all 1s, these bit times and the stop bits time count toward the full character time of logic high, 10 to 13 bit times, needed for the receiver to detect an idle line. when ilt is set, the receiver doesn't start counting idle bit times until after the stop bits. the stop bits and any logic high bit times at the end of the previous character do not count toward the full character time of logic high needed for the receiver to detect an idle line. to clear idle, write logic 1 to the idle flag. after idle has been cleared, it cannot become set again until after a new character has been received and rdrf has been set. idle is set only once even if the receive line remains idle for an extended period. 0 no idle line detected. 1 idle line was detected. 3 or receiver overrun flag or is set when a new serial character is ready to be transferred to the receive data buffer, but the previously received character has not been read from uart _d yet. in this case, the new character, and all associated error information, is lost because there is no room to move it into uart _d. to clear or, write a logic 1 to the or flag. 0 no overrun. 1 receive overrun (new uart data lost). 2 nf noise flag the advanced sampling technique used in the receiver takes three samples in each of the received bits. if any of these samples disagrees with the rest of the samples within any bit time in the frame, the flag nf is set at the same time as rdrf is set for the character. to clear nf, write logic one to the nf. 0 no noise detected. 1 noise detected in the received character in uart _d. 1 fe framing error flag fe is set at the same time as rdrf when the receiver detects a logic 0 where a stop bit was expected. this suggests the receiver was not properly aligned to a character frame. to clear fe, write a logic one to the fe flag. 0 no framing error detected. this does not guarantee the framing is correct. 1 framing error. 0 pf parity error flag pf is set at the same time as rdrf when parity is enabled (pe = 1) and the parity bit in the received character does not agree with the expected parity value. to clear pf, write a logic one to the pf. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 628 freescale semiconductor, inc.
uart x _s1 field descriptions (continued) field description 0 no parity error. 1 parity error. 36.2.6 uart status register 2 (uart x _s2) this register contains one read-only status flag. when using an internal oscillator in a lin system, it is necessary to raise the break detection threshold one bit time. under the worst case timing conditions allowed in lin, it is possible that a 0x00 data character can appear to be 10.26 bit times long at a slave running 14% faster than the master. this would trigger normal break detection circuitry designed to detect a 10-bit break symbol. when the lbkde bit is set, framing errors are inhibited and the break detection threshold increases, preventing false detection of a 0x00 data character as a lin break symbol. address: 4006_a000h base + 5h offset = 4006_a005h bit 7 6 5 4 3 2 1 0 read lbkdif rxedgif msbf rxinv rwuid brk13 lbkde raf write reset 0 0 0 0 0 0 0 0 uart x _s2 field descriptions field description 7 lbkdif lin break detect interrupt flag lbkdif is set when the lin break detect circuitry is enabled and a lin break character is detected. lbkdif is cleared by writing a 1 to it. 0 no lin break character has been detected. 1 lin break character has been detected. 6 rxedgif uart _rx pin active edge interrupt flag rxedgif is set when an active edge, falling if rxinv = 0, rising if rxinv=1, on the uart _rx pin occurs. rxedgif is cleared by writing a 1 to it. 0 no active edge on the receive pin has occurred. 1 an active edge on the receive pin has occurred. 5 msbf msb first setting this bit reverses the order of the bits that are transmitted and received on the wire. this bit does not affect the polarity of the bits, the location of the parity bit or the location of the start or stop bits. this bit should only be changed when the transmitter and receiver are both disabled. table continues on the next page... chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 629
uart x _s2 field descriptions (continued) field description 0 lsb (bit0) is the first bit that is transmitted following the start bit. further, the first bit received after the start bit is identified as bit0. 1 msb (bit9, bit8, bit7 or bit6) is the first bit that is transmitted following the start bit depending on the setting of c1[m], c1[pe] and c4[m10]. further, the first bit received after the start bit is identified as bit9, bit8, bit7 or bit6 depending on the setting of c1[m] and c1[pe]. 4 rxinv receive data inversion setting this bit reverses the polarity of the received data input. note: setting rxinv inverts the uart _rxd input for all cases: data bits, start and stop bits, break, and idle. 0 receive data not inverted. 1 receive data inverted. 3 rwuid receive wake up idle detect rwuid controls whether the idle character that wakes up the receiver sets the idle bit. this bit should only be changed when the receiver is disabled. 0 during receive standby state (rwu = 1), the idle bit does not get set upon detection of an idle character. 1 during receive standby state (rwu = 1), the idle bit gets set upon detection of an idle character. 2 brk13 break character generation length brk13 selects a longer transmitted break character length. detection of a framing error is not affected by the state of this bit. this bit should only be changed when the transmitter is disabled. 0 break character is transmitted with length of 10 bit times (if m = 0, sbns = 0) or 11 (if m = 1, sbns = 0 or m = 0, sbns = 1) or 12 (if m = 1, sbns = 1 or m10 = 1, snbs = 0) or 13 (if m10 = 1, snbs = 1). 1 break character is transmitted with length of 13 bit times (if m = 0, sbns = 0) or 14 (if m = 1, sbns = 0 or m = 0, sbns = 1) or 15 (if m = 1, sbns = 1 or m10 = 1, snbs = 0) or 16 (if m10 = 1, snbs = 1). 1 lbkde lin break detection enable lbkde selects a longer break character detection length. while lbkde is set, framing error (fe) and receive data register full (rdrf) flags are prevented from setting. 0 break character is detected at length 10 bit times (if m = 0, sbns = 0) or 11 (if m = 1, sbns = 0 or m = 0, sbns = 1) or 12 (if m = 1, sbns = 1 or m10 = 1, snbs = 0) or 13 (if m10 = 1, snbs = 1). 1 break character is detected at length of 11 bit times (if m = 0, sbns = 0) or 12 (if m = 1, sbns = 0 or m = 0, sbns = 1) or 14 (if m = 1, sbns = 1 or m10 = 1, snbs = 0) or 15 (if m10 = 1, snbs = 1). 0 raf receiver active flag raf is set when the uart receiver detects the beginning of a valid start bit, and raf is cleared automatically when the receiver detects an idle line. 0 uart receiver idle waiting for a start bit. 1 uart receiver active ( uart _rxd input not idle). register definition kl04 sub-family reference manual, rev. 3.1, november 2012 630 freescale semiconductor, inc.
36.2.7 uart control register 3 (uart x _c3) address: 4006_a000h base + 6h offset = 4006_a006h bit 7 6 5 4 3 2 1 0 read r8t9 r9t8 txdir txinv orie neie feie peie write reset 0 0 0 0 0 0 0 0 uart x _c3 field descriptions field description 7 r8t9 receive bit 8 / transmit bit 9 when the uart is configured for 9-bit data (m = 1), r8 can be thought of as a ninth receive data bit to the left of the msb of the buffered data in the uart_d register. when reading 9-bit data, read r8 before reading uart_d because reading uart_d completes automatic flag clearing sequences that could allow r8 and uart_d to be overwritten with new data. when the uart is configured for 10-bit data (m10 = 1), t9 may be thought of as a tenth transmit data bit. when writing 10-bit data, the entire 10-bit value is transferred to the uart transmit buffer when uart_d is written so t9 and t8 should be written, if it needs to change from its previous value, before uart_d is written. if t9 and t8 do not need to change in the new value, such as when it is used to generate mark or space parity, they need not be written each time uart_d is written. 6 r9t8 receive bit 9 / transmit bit 8 when the uart is configured for 9-bit data (m = 1), t8 may be thought of as a ninth transmit data bit to the left of the msb of the data in the uart_d register. when writing 9-bit data, the entire 9-bit value is transferred to the uart transmit buffer after uart_d is written so t8 should be written, if it needs to change from its previous value, before uart_d is written. if t8 does not need to change in the new value, such as when it is used to generate mark or space parity, it need not be written each time uart_d is written. when the uart is configured for 10-bit data (m10 = 1), r9 can be thought of as a tenth receive data bit. when reading 10-bit data, read r9 and r8 before reading uart_d because reading uart_d completes automatic flag clearing sequences that could allow r8, r9 and uart_d to be overwritten with new data. 5 txdir uart _tx pin direction in single-wire mode when the uart is configured for single-wire half-duplex operation (loops = rsrc = 1), this bit determines the direction of data at the uart_txd pin. when clearing txdir, the transmitter will finish receiving the current character (if any) before the receiver starts receiving data from the uart_txd pin. 0 uart _txd pin is an input in single-wire mode. 1 uart _txd pin is an output in single-wire mode. 4 txinv transmit data inversion setting this bit reverses the polarity of the transmitted data output. note: setting txinv inverts the uart _txd output for all cases: data bits, start and stop bits, break, and idle. 0 transmit data not inverted. 1 transmit data inverted. 3 orie overrun interrupt enable this bit enables the overrun flag (or) to generate hardware interrupt requests. table continues on the next page... chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 631
uart x _c3 field descriptions (continued) field description 0 or interrupts disabled; use polling. 1 hardware interrupt requested when or is set. 2 neie noise error interrupt enable this bit enables the noise flag (nf) to generate hardware interrupt requests. 0 nf interrupts disabled; use polling. 1 hardware interrupt requested when nf is set. 1 feie framing error interrupt enable this bit enables the framing error flag (fe) to generate hardware interrupt requests. 0 fe interrupts disabled; use polling. 1 hardware interrupt requested when fe is set. 0 peie parity error interrupt enable this bit enables the parity error flag (pf) to generate hardware interrupt requests. 0 pf interrupts disabled; use polling). 1 hardware interrupt requested when pf is set. 36.2.8 uart data register (uart x _d) this register is actually two separate registers. reads return the contents of the read-only receive data buffer and writes go to the write-only transmit data buffer. reads and writes of this register are also involved in the automatic flag clearing mechanisms for some of the uart status flags. address: 4006_a000h base + 7h offset = 4006_a007h bit 7 6 5 4 3 2 1 0 read r7t7 r6t6 r5t5 r4t4 r3t3 r2t2 r1t1 r0t0 write reset 0 0 0 0 0 0 0 0 uart x _d field descriptions field description 7 r7t7 read receive data buffer 7 or write transmit data buffer 7. 6 r6t6 read receive data buffer 6 or write transmit data buffer 6. 5 r5t5 read receive data buffer 5 or write transmit data buffer 5. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 632 freescale semiconductor, inc.
uart x _d field descriptions (continued) field description 4 r4t4 read receive data buffer 4 or write transmit data buffer 4. 3 r3t3 read receive data buffer 3 or write transmit data buffer 3. 2 r2t2 read receive data buffer 2 or write transmit data buffer 2. 1 r1t1 read receive data buffer 1 or write transmit data buffer 1. 0 r0t0 read receive data buffer 0 or write transmit data buffer 0. 36.2.9 uart match address registers 1 (uart x _ma1) the ma1 and ma2 registers are compared to input data addresses when the most significant bit is set and the associated c4[maen] bit is set. if a match occurs, the following data is transferred to the data register. if a match fails, the following data is discarded. software should only write a ma register when the associated c4[maen] bit is clear. address: 4006_a000h base + 8h offset = 4006_a008h bit 7 6 5 4 3 2 1 0 read ma write reset 0 0 0 0 0 0 0 0 uart x _ma1 field descriptions field description 7C0 ma match address chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 633
36.2.10 uart match address registers 2 (uart x _ma2) the ma1 and ma2 registers are compared to input data addresses when the most significant bit is set and the associated c4[maen] bit is set. if a match occurs, the following data is transferred to the data register. if a match fails, the following data is discarded. software should only write a ma register when the associated c4[maen] bit is clear. address: 4006_a000h base + 9h offset = 4006_a009h bit 7 6 5 4 3 2 1 0 read ma write reset 0 0 0 0 0 0 0 0 uart x _ma2 field descriptions field description 7C0 ma match address 36.2.11 uart control register 4 (uart x _c4) address: 4006_a000h base + ah offset = 4006_a00ah bit 7 6 5 4 3 2 1 0 read maen1 maen2 m10 osr write reset 0 0 0 0 1 1 1 1 uart x _c4 field descriptions field description 7 maen1 match address mode enable 1 refer to match address operation for more information. 0 all data received is transferred to the data buffer if maen2 is cleared. 1 all data received with the most significant bit cleared, is discarded. all data received with the most significant bit set, is compared with contents of ma1 register. if no match occurs, the data is discarded. if match occurs, data is transferred to the data buffer. 6 maen2 match address mode enable 2 refer to match address operation for more information. 0 all data received is transferred to the data buffer if maen1 is cleared. 1 all data received with the most significant bit cleared, is discarded. all data received with the most significant bit set, is compared with contents of ma2 register. if no match occurs, the data is discarded. if match occurs, data is transferred to the data buffer. table continues on the next page... register definition kl04 sub-family reference manual, rev. 3.1, november 2012 634 freescale semiconductor, inc.
uart x _c4 field descriptions (continued) field description 5 m10 10-bit mode select the m10 bit causes a tenth bit to be part of the serial transmission. this bit should only be changed when the transmitter and receiver are both disabled. 0 receiver and transmitter use 8-bit or 9-bit data characters. 1 receiver and transmitter use 10-bit data characters. 4C0 osr over sampling ratio this field configures the oversampling ratio for the receiver between 4x (00011) and 32x (11111). writing an invalid oversampling ratio will default to an oversampling ratio of 16 (01111). this field should only be changed when the transmitter and receiver are both disabled. 36.2.12 uart control register 5 (uart x _c5) address: 4006_a000h base + bh offset = 4006_a00bh bit 7 6 5 4 3 2 1 0 read tdmae 0 rdmae 0 bothedge resyncdi s write reset 0 0 0 0 0 0 0 0 uart x _c5 field descriptions field description 7 tdmae transmitter dma enable tdmae configures the transmit data register empty flag, s1[tdre], to generate a dma request. 0 dma request disabled. 1 dma request enabled. 6 reserved this field is reserved. this read-only field is reserved and always has the value 0. 5 rdmae receiver full dma enable rdmae configures the receiver data register full flag, s1[rdrf], to generate a dma request. 0 dma request disabled. 1 dma request enabled. 4C2 reserved this field is reserved. this read-only field is reserved and always has the value 0. 1 bothedge both edge sampling enables sampling of the received data on both edges of the baud rate clock, effectively doubling the number of times the receiver samples the input data for a given oversampling ratio. this bit must be set for oversampling ratios between x4 and x7 and is optional for higher oversampling ratios. this bit should only be changed when the receiver is disabled. table continues on the next page... chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 635
uart x _c5 field descriptions (continued) field description 0 receiver samples input data using the rising edge of the baud rate clock. 1 receiver samples input data using the rising and falling edge of the baud rate clock. 0 resyncdis resynchronization disable when set, disables the resynchronization of the received data word when a data one followed by data zero transition is detected. this bit should only be changed when the receiver is disabled. 0 resynchronization during received data word is supported 1 resynchronization during received data word is disabled 36.3 functional description the uart supports full-duplex, asynchronous, nrz serial communication and comprises a baud rate generator, transmitter, and receiver block. the transmitter and receiver operate independently, although they use the same baud rate generator. the following describes each of the blocks of the uart. 36.3.1 baud rate generation a 13-bit modulus counter in the baud rate generator derive the baud rate for both the receiver and the transmitter. the value from 1 to 8191 written to sbr[12:0] determines the baud clock divisor for the asynchronous uart baud clock. the sbr bits are in the uart baud rate registers, bdh and bdl. the baud rate clock drives the receiver, while the transmitter is driven by the baud rate clock divided by the over sampling ratio. depending on the over sampling ratio, the receiver has an acquisition rate of 4 to 32 samples per bit time. figure 36-27. uart baud rate generation baud rate generation is subject to two sources of error: ? integer division of the module clock may not give the exact target frequency. ? synchronization with the asynchronous uart baud clock can cause phase shift. 36.3.2 transmitter functional description this section describes the overall block diagram for the uart transmitter, as well as specialized functions for sending break and idle characters. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 636 freescale semiconductor, inc.
the transmitter output (uart_tx) idle state defaults to logic high, c3[txinv] is cleared following reset. the transmitter output is inverted by setting c3[txinv]. the transmitter is enabled by setting the c2[te] bit. this queues a preamble character that is one full character frame of the idle state. the transmitter then remains idle until data is available in the transmit data buffer. programs store data into the transmit data buffer by writing to the uart data register. the central element of the uart transmitter is the transmit shift register that is 10-bit to 13 bits long depending on the setting in the c1[m], c2[m10] and bdh[sbns] control bits. for the remainder of this section, assume c1[m], c2[m10] and bdh[sbns] are cleared, selecting the normal 8-bit data mode. in 8-bit data mode, the shift register holds a start bit, eight data bits, and a stop bit. when the transmit shift register is available for a new uart character, the value waiting in the transmit data register is transferred to the shift register, synchronized with the baud rate clock, and the transmit data register empty (s1[tdre]) status flag is set to indicate another character may be written to the transmit data buffer at uart_d. if no new character is waiting in the transmit data buffer after a stop bit is shifted out the uart_tx pin, the transmitter sets the transmit complete flag and enters an idle mode, with uart_tx high, waiting for more characters to transmit. writing 0 to c2[te] does not immediately disable the transmitter. the current transmit activity in progress must first be completed. this includes data characters in progress, queued idle characters, and queued break characters. 36.3.2.1 send break and queued idle the uart_c2[sbk] bit sends break characters originally used to gain the attention of old teletype receivers. break characters are a full character time of logic 0, 10-bit to 12- bit times including the start and stop bits. a longer break of 13-bit times can be enabled by setting uart_s2[brk13]. normally, a program would wait for uart_s1[tdre] to become set to indicate the last character of a message has moved to the transmit shifter, write 1, and then write 0 to the uart_c2[sbk] bit. this action queues a break character to be sent as soon as the shifter is available. if uart_c2[sbk] remains 1 when the queued break moves into the shifter, synchronized to the baud rate clock, an additional break character is queued. if the receiving device is another freescale semiconductor uart, the break characters are received as 0s in all data bits and a framing error (uart_s1[fe] = 1) occurs. when idle-line wakeup is used, a full character time of idle (logic 1) is needed between messages to wake up any sleeping receivers. normally, a program would wait for uart_s1[tdre] to become set to indicate the last character of a message has moved to chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 637
the transmit shifter, then write 0 and then write 1 to the uart_c2[te] bit. this action queues an idle character to be sent as soon as the shifter is available. as long as the character in the shifter does not finish whileuart_c2[te] is cleared, the uart transmitter never actually releases control of the uart_tx pin. the length of the break character is affected by the uart_s2[brk13], uart_c1[m] and uart_c4[m10] bits as shown below. table 36-27. break character length brk13 m m10 sbns break character length 0 0 0 0 10 bit times 0 0 0 1 11 bit times 0 1 0 0 11 bit times 0 1 0 1 12 bit times 0 x 1 0 12 bit times 0 x 1 1 13 bit times 1 0 0 0 13 bit times 1 0 0 1 14 bit times 1 1 0 0 14 bit times 1 1 0 1 15 bit times 1 x 1 0 15 bit times 1 x 1 1 16 bit times 36.3.3 receiver functional description in this section, the receiver block diagram is a guide for the overall receiver functional description. next, the data sampling technique used to reconstruct receiver data is described in more detail. finally, two variations of the receiver wakeup function are explained. the receiver input is inverted by setting uart_s2[rxinv]. the receiver is enabled by setting the uart_c2[re] bit. character frames consist of a start bit of logic 0, eight to ten data bits (msb or lsb first), and one or two stop bits of logic 1. for information about 9-bit or 10-bit data mode, refer to 8-bit, 9-bit and 10-bit data modes . for the remainder of this discussion, assume the uart is configured for normal 8-bit data mode. after receiving the stop bit into the receive shifter, and provided the receive data register is not already full, the data character is transferred to the receive data register and the receive data register full (uart_s1[rdrf]) status flag is set. if uart_s1[rdrf] was already set indicating the receive data register (buffer) was already full, the overrun (or) functional description kl04 sub-family reference manual, rev. 3.1, november 2012 638 freescale semiconductor, inc.
status flag is set and the new data is lost. because the uart receiver is double-buffered, the program has one full character time after uart_s1[rdrf] is set before the data in the receive data buffer must be read to avoid a receiver overrun. when a program detects that the receive data register is full (uart_s1[rdrf] = 1), it gets the data from the receive data register by reading uart_d. refer to interrupts and status flags for details about flag clearing. 36.3.3.1 data sampling technique the uart receiver supports an oversampling rate of between 4 and 32 of the baud rate clock for sampling. the receiver starts by taking logic level samples at the oversampling rate times the baud rate to search for a falling edge on the uart_rx serial data input pin. a falling edge is defined as a logic 0 sample after three consecutive logic 1 samples. the oversampling baud rate clock divides the bit time into 4 to 32 segments from 1 to osr (where osr is the configured oversampling ratio). when a falling edge is located, three more samples are taken at (osr/2), (osr/2)+1, and (osr/2)+2 to make sure this was a real start bit and not merely noise. if at least two of these three samples are 0, the receiver assumes it is synchronized to a receive character. if another falling edge is detected before the receiver is considered synchronized, the receiver restarts the sampling from the first segment. the receiver then samples each bit time, including the start and stop bits, at (osr/2), (osr/2)+1, and (osr/2)+2 to determine the logic level for that bit. the logic level is interpreted to be that of the majority of the samples taken during the bit time. if any sample in any bit time, including the start and stop bits, in a character frame fails to agree with the logic level for that bit, the noise flag (uart_s1[nf]) is set when the received character is transferred to the receive data buffer. when the uart receiver is configured to sample on both edges of the baud rate clock, the number of segments in each received bit is effectively doubled (from 1 to osr*2). the start and data bits are then sampled at osr, osr+1 and osr+2. sampling on both edges of the clock must be enabled for oversampling rates of 4 to 7 and is optional for higher oversampling rates. the falling edge detection logic continuously looks for falling edges. if an edge is detected, the sample clock is resynchronized to bit times (unless resynchronization has been disabled). this improves the reliability of the receiver in the presence of noise or mismatched baud rates. it does not improve worst case analysis because some characters do not have any extra falling edges anywhere in the character frame. chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 639
in the case of a framing error, provided the received character was not a break character, the sampling logic that searches for a falling edge is filled with three logic 1 samples so that a new start bit can be detected almost immediately. 36.3.3.2 receiver wakeup operation receiver wakeup is a hardware mechanism that allows an uart receiver to ignore the characters in a message intended for a different uart receiver. in such a system, all receivers evaluate the first character(s) of each message, and as soon as they determine the message is intended for a different receiver, they write logic 1 to the receiver wake up control bit(uart_c2[rwu]). when rwu bit is set, the status flags associated with the receiver, with the exception of the idle bit, idle, when uart_s2[rwuid] bit is set, are inhibited from setting, thus eliminating the software overhead for handling the unimportant message characters. at the end of a message, or at the beginning of the next message, all receivers automatically force uart_c2[rwu] to 0 so all receivers wake up in time to look at the first character(s) of the next message. 36.3.3.2.1 idle-line wakeup when wake is cleared, the receiver is configured for idle-line wakeup. in this mode, uart_c2[rwu] is cleared automatically when the receiver detects a full character time of the idle-line level. the uart_c1[m] and uart_c4[m10] control bit selects 8-bit to 10-bit data mode and the uart_bdh[sbns] bit selects 1-bit or 2-bit stop bit number that determines how many bit times of idle are needed to constitute a full character time, 10 to 13 bit times because of the start and stop bits. when uart_c2[rwu] is one and uart_s2[rwuid] is zero, the idle condition that wakes up the receiver does not set the uart_s1[idle] flag. the receiver wakes up and waits for the first data character of the next message that sets the uart_s1[rdrf] flag and generates an interrupt if enabled. when uart_s2[rwuid] is one, any idle condition sets the uart_s1[idle] flag and generates an interrupt if enabled, regardless of whether uart_c2[rwu] is zero or one. the idle-line type (uart_c1[ilt]) control bit selects one of two ways to detect an idle line. when uart_c1[ilt] is cleared, the idle bit counter starts after the start bit so the stop bit and any logic 1s at the end of a character count toward the full character time of idle. when uart_c1[ilt] is set, the idle bit counter does not start until after the stop bit time, so the idle detection is not affected by the data in the last character of the previous message. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 640 freescale semiconductor, inc.
36.3.3.2.2 address-mark wakeup when wake is set, the receiver is configured for address-mark wakeup. in this mode, uart_c2[rwu] is cleared automatically when the receiver detects a logic 1 in the most significant bit of a received character. address-mark wakeup allows messages to contain idle characters, but requires the msb be reserved for use in address frames. the logic 1 in the msb of an address frame clears the uart_c2[rwu] bit before the stop bits are received and sets the uart_s1[rdrf] flag. in this case, the character with the msb set is received even though the receiver was sleeping during most of this character time. 36.3.3.2.3 match address operation match address operation is enabled when the uart_c4[maen1] or uart_c4[maen2] bit is set. in this function, a frame received by the uart_rx pin with a logic 1 in the bit position immediately preceding the stop bit is considered an address and is compared with the associated ma1 or ma2 register. the frame is only transferred to the receive buffer, and uart_s1[rdrf] is set, if the comparison matches. all subsequent frames received with a logic 0 in the bit position immediately preceding the stop bit are considered to be data associated with the address and are transferred to the receive data buffer. if no marked address match occurs then no transfer is made to the receive data buffer, and all following frames with logic zero in the bit position immediately preceding the stop bit are also discarded. if both the uart_c4[maen1] and uart_c4[maen2] bits are negated, the receiver operates normally and all data received is transferred to the receive data buffer. match address operation functions in the same way for both ma1 and ma2 registers. ? if only one of uart_c4[maen1] and uart_c4[maen2] is asserted, a marked address is compared only with the associated match register and data is transferred to the receive data buffer only on a match. ? if uart_c4[maen1] and uart_c4[maen2] are asserted, a marked address is compared with both match registers and data is transferred only on a match with either register. 36.3.4 additional uart functions the following sections describe additional uart functions. chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 641
36.3.4.1 8-bit, 9-bit and 10-bit data modes the uart system, transmitter and receiver, can be configured to operate in 9-bit data mode by setting the uart_c1[m] or 10-bit data mode by setting uart_c4[m10]. in 9- bit mode, there is a ninth data bit to the left of the msb of the uart data register, in 10- bit mode there is a tenth data bit. for the transmit data buffer, these bits are stored in t8 and t9 in uart_c3. for the receiver, these bits are held in uart_c3[r8] and uart_c3[r9]. for coherent writes to the transmit data buffer, write to uart_c3[t8] and uart_c3[t9] before writing to uart_d. if the bit values to be transmitted as the ninth and tenth bit of a new character are the same as for the previous character, it is not necessary to write to t8 and t9 again. when data is transferred from the transmit data buffer to the transmit shifter, the value in t8 and t9 is copied at the same time data is transferred from uart_d to the shifter. the 9-bit data mode is typically used with parity to allow eight bits of data plus the parity in the ninth bit, or it is used with address-mark wakeup so the ninth data bit can serve as the wakeup bit. the 10-bit data mode is typically used with parity and address-mark wakeup so the ninth data bit can serve as the wakeup bit and the tenth bit as the parity bit. in custom protocols, the ninth and/or tenth bits can also serve as software-controlled markers. 36.3.4.2 loop mode when uart_c1[loops] is set, the uart_c1[rsrc] bit in the same register chooses between loop mode (uart_c1[rsrc] = 0) or single-wire mode (uart_c1[rsrc] = 1). loop mode is sometimes used to check software, independent of connections in the external system, to help isolate system problems. in this mode, the transmitter output is internally connected to the receiver input and the uart_rx pin is not used by the uart. 36.3.4.3 single-wire operation when uart_c1[loops] is set, the rsrc bit in the same register chooses between loop mode (uart_c1[rsrc] = 0) or single-wire mode (uart_c1[rsrc] = 1). single-wire mode implements a half-duplex serial connection. the receiver is internally connected to the transmitter output and to the uart_tx pin (the uart_rx pin is not used). functional description kl04 sub-family reference manual, rev. 3.1, november 2012 642 freescale semiconductor, inc.
in single-wire mode, the uart_c3[txdir] bit controls the direction of serial data on the uart_tx pin. when uart_c3[txdir] is cleared, the uart_tx pin is an input to the uart receiver and the transmitter is temporarily disconnected from the uart_tx pin so an external device can send serial data to the receiver. when uart_c3[txdir] is set, the uart_txd pin is an output driven by the transmitter, the internal loop back connection is disabled, and as a result the receiver cannot receive characters that are sent out by the transmitter. 36.3.5 interrupts and status flags the uart system generates three separate interrupts to reduce the amount of software needed to isolate the cause of the interrupt. one interrupt is associated with the transmitter for tdre and tc events. another interrupt is associated with the receiver for rdrf, idle, rxedgif, and lbkdif events. a third interrupt is used for or, nf, fe, and pf error conditions. each of these ten interrupt sources can be separately masked by local interrupt enable masks. the flags can be polled by software when the local masks are cleared to disable generation of hardware interrupt requests. the uart transmitter has two status flags that can optionally generate hardware interrupt requests. transmit data register empty (uart_s1[tdre]) indicates when there is room in the transmit data buffer to write another transmit character to uart_d. if the transmit interrupt enable (uart_c2[tie]) bit is set, a hardware interrupt is requested when uart_s1[tdre] is set. transmit complete (uart_s1[tc]) indicates that the transmitter is finished transmitting all data, preamble, and break characters and is idle with uart_tx at the inactive level. this flag is often used in systems with modems to determine when it is safe to turn off the modem. if the transmit complete interrupt enable (uart_c2[tcie]) bit is set, a hardware interrupt is requested when uart_s1[tc] is set. instead of hardware interrupts, software polling may be used to monitor the uart_s1[tdre] and uart_s1[tc] status flags if the corresponding uart_c2[tie] or uart_c2[tcie] local interrupt masks are cleared. when a program detects that the receive data register is full (uart_s1[rdrf] = 1), it gets the data from the receive data register by reading uart_d. the uart_s1[rdrf] flag is cleared by reading uart_d. the idle status flag includes logic that prevents it from getting set repeatedly when the uart_rx line remains idle for an extended period of time. idle is cleared by writing 1 to the uart_s1[idle] flag. after uart_s1[idle] has been cleared, it cannot become set again until the receiver has received at least one new character and has set uart_s1[rdrf]. chapter 36 universal asynchronous receiver/transmitter (uart0) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 643
if the associated error was detected in the received character that caused uart_s1[rdrf] to be set, the error flags - noise flag (uart_s1[nf]), framing error (uart_s1[fe]), and parity error flag (uart_s1[pf]) - are set at the same time as uart_s1[rdrf]. these flags are not set in overrun cases. if uart_s1[rdrf] was already set when a new character is ready to be transferred from the receive shifter to the receive data buffer, the overrun (uart_s1[or]) flag is set instead of the data along with any associated nf, fe, or pf condition is lost. at any time, an active edge on the uart_rx serial data input pin causes the uart_s2[rxedgif] flag to set. the uart_s2[rxedgif] flag is cleared by writing a 1 to it. this function depends on the receiver being enabled (uart_c2[re] = 1). functional description kl04 sub-family reference manual, rev. 3.1, november 2012 644 freescale semiconductor, inc.
chapter 37 general-purpose input/output (gpio) 37.1 introduction note for the chip-specific implementation details of this module's instances see the chip configuration information. the general-purpose input and output (gpio) module communicates to the processor core via a zero wait state interface for maximum pin performance. the gpio registers support 8-bit, 16-bit or 32-bit accesses. the gpio data direction and output data registers control the direction and output data of each pin when the pin is configured for the gpio function. the gpio input data register displays the logic value on each pin when the pin is configured for any digital function, provided the corresponding port control and interrupt module for that pin is enabled. efficient bit manipulation of the general-purpose outputs is supported through the addition of set, clear, and toggle write-only registers for each port output data register. 37.1.1 features ? features of the gpio module include: ? pin input data register visible in all digital pin-multiplexing modes ? pin output data register with corresponding set/clear/toggle registers ? pin data direction register ? zero wait state access to gpio registers through ioport note gpio module is clocked by system clock. kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 645
37.1.2 modes of operation the following table depicts different modes of operation and the behavior of the gpio module in these modes. table 37-1. modes of operation modes of operation description run the gpio module operates normally. wait the gpio module operates normally. stop the gpio module is disabled. debug the gpio module operates normally. 37.1.3 gpio signal descriptions table 37-2. gpio signal descriptions gpio signal descriptions description i/o porta31Cporta0 general-purpose input/output i/o portb31Cportb0 general-purpose input/output i/o note not all pins within each port are implemented on each device. see the chapter on signal multiplexing for the number of gpio ports available in the device. introduction kl04 sub-family reference manual, rev. 3.1, november 2012 646 freescale semiconductor, inc.
37.1.3.1 detailed signal description table 37-3. gpio interface-detailed signal descriptions signal i/o description porta31Cporta0 portb31Cportb0 i/o general-purpose input/output state meaning asserted: the pin is logic 1. deasserted: the pin is logic 0. timing assertion: when output, this signal occurs on the rising- edge of the system clock. for input, it may occur at any time and input may be asserted asynchronously to the system clock. deassertion: when output, this signal occurs on the rising-edge of the system clock. for input, it may occur at any time and input may be asserted asynchronously to the system clock. 37.2 memory map and register definition any read or write access to the gpio memory space that is outside the valid memory map results in a bus error. gpio memory map absolute address (hex) register name width (in bits) access reset value section/ page 400f_f000 port data output register (gpioa_pdor) 32 r/w 0000_0000h 37.2.1/648 400f_f004 port set output register (gpioa_psor) 32 w (always reads 0) 0000_0000h 37.2.2/649 400f_f008 port clear output register (gpioa_pcor) 32 w (always reads 0) 0000_0000h 37.2.3/649 400f_f00c port toggle output register (gpioa_ptor) 32 w (always reads 0) 0000_0000h 37.2.4/650 400f_f010 port data input register (gpioa_pdir) 32 r 0000_0000h 37.2.5/650 400f_f014 port data direction register (gpioa_pddr) 32 r/w 0000_0000h 37.2.6/651 400f_f040 port data output register (gpiob_pdor) 32 r/w 0000_0000h 37.2.1/648 table continues on the next page... chapter 37 general-purpose input/output (gpio) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 647
gpio memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page 400f_f044 port set output register (gpiob_psor) 32 w (always reads 0) 0000_0000h 37.2.2/649 400f_f048 port clear output register (gpiob_pcor) 32 w (always reads 0) 0000_0000h 37.2.3/649 400f_f04c port toggle output register (gpiob_ptor) 32 w (always reads 0) 0000_0000h 37.2.4/650 400f_f050 port data input register (gpiob_pdir) 32 r 0000_0000h 37.2.5/650 400f_f054 port data direction register (gpiob_pddr) 32 r/w 0000_0000h 37.2.6/651 37.2.1 port data output register (gpio x _pdor) this register configures the logic levels that are driven on each general-purpose output pins. note do not modify pin configuration registers associated with pins not available in your selected package. all un-bonded pins not available in your package will default to disable state for lowest power consumption. address: base address + 0h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r pdo w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gpio x _pdor field descriptions field description 31C0 pdo port data output register bits for un-bonded pins return a undefined value when read. 0 logic level 0 is driven on pin, provided pin is configured for general-purpose output. 1 logic level 1 is driven on pin, provided pin is configured for general-purpose output. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 648 freescale semiconductor, inc.
37.2.2 port set output register (gpio x _psor) this register configures whether to set the fields of the pdor. address: base address + 4h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w ptso reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gpio x _psor field descriptions field description 31C0 ptso port set output writing to this register will update the contents of the corresponding bit in the pdor as follows: 0 corresponding bit in pdorn does not change. 1 corresponding bit in pdorn is set to logic 1. 37.2.3 port clear output register (gpio x _pcor) this register configures whether to clear the fields of pdor. address: base address + 8h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w ptco reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gpio x _pcor field descriptions field description 31C0 ptco port clear output writing to this register will update the contents of the corresponding bit in the port data output register (pdor) as follows: 0 corresponding bit in pdorn does not change. 1 corresponding bit in pdorn is cleared to logic 0. chapter 37 general-purpose input/output (gpio) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 649
37.2.4 port toggle output register (gpio x _ptor) address: base address + ch offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w ptto reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gpio x _ptor field descriptions field description 31C0 ptto port toggle output writing to this register will update the contents of the corresponding bit in the pdor as follows: 0 corresponding bit in pdorn does not change. 1 corresponding bit in pdorn is set to the inverse of its existing logic state. 37.2.5 port data input register (gpio x _pdir) note do not modify pin configuration registers associated with pins not available in your selected package. all un-bonded pins not available in your package will default to disable state for lowest power consumption. address: base address + 10h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r pdi w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gpio x _pdir field descriptions field description 31C0 pdi port data input reads 0 at the unimplemented pins for a particular device. pins that are not configured for a digital function read 0. if the port control and interrupt module is disabled, then the corresponding bit in pdir does not update. 0 pin logic level is logic 0, or is not configured for use by digital function. 1 pin logic level is logic 1. memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 650 freescale semiconductor, inc.
37.2.6 port data direction register (gpio x _pddr) the pddr configures the individual port pins for input or output. address: base address + 14h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r pdd w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 gpio x _pddr field descriptions field description 31C0 pdd port data direction configures individual port pins for input or output. 0 pin is configured as general-purpose input, for the gpio function. 1 pin is configured as general-purpose output, for the gpio function. 37.3 fgpio memory map and register definition any read or write access to the fgpio memory space that is outside the valid memory map results in a bus error. all register accesses complete with zero wait states, except error accesses which complete with one wait state. fgpio memory map absolute address (hex) register name width (in bits) access reset value section/ page f80f_f000 port data output register (fgpioa_pdor) 32 r/w 0000_0000h 37.3.1/652 f80f_f004 port set output register (fgpioa_psor) 32 w (always reads 0) 0000_0000h 37.3.2/652 f80f_f008 port clear output register (fgpioa_pcor) 32 w (always reads 0) 0000_0000h 37.3.3/653 f80f_f00c port toggle output register (fgpioa_ptor) 32 w (always reads 0) 0000_0000h 37.3.4/653 f80f_f010 port data input register (fgpioa_pdir) 32 r 0000_0000h 37.3.5/654 f80f_f014 port data direction register (fgpioa_pddr) 32 r/w 0000_0000h 37.3.6/654 f80f_f040 port data output register (fgpiob_pdor) 32 r/w 0000_0000h 37.3.1/652 table continues on the next page... chapter 37 general-purpose input/output (gpio) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 651
fgpio memory map (continued) absolute address (hex) register name width (in bits) access reset value section/ page f80f_f044 port set output register (fgpiob_psor) 32 w (always reads 0) 0000_0000h 37.3.2/652 f80f_f048 port clear output register (fgpiob_pcor) 32 w (always reads 0) 0000_0000h 37.3.3/653 f80f_f04c port toggle output register (fgpiob_ptor) 32 w (always reads 0) 0000_0000h 37.3.4/653 f80f_f050 port data input register (fgpiob_pdir) 32 r 0000_0000h 37.3.5/654 f80f_f054 port data direction register (fgpiob_pddr) 32 r/w 0000_0000h 37.3.6/654 37.3.1 port data output register (fgpio x _pdor) this register configures the logic levels that are driven on each general-purpose output pins. address: base address + 0h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r pdo w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 fgpio x _pdor field descriptions field description 31C0 pdo port data output unimplemented pins for a particular device read as zero. 0 logic level 0 is driven on pin, provided pin is configured for general-purpose output. 1 logic level 1 is driven on pin, provided pin is configured for general-purpose output. 37.3.2 port set output register (fgpio x _psor) this register configures whether to set the fields of the pdor. address: base address + 4h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w ptso reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 fgpio memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 652 freescale semiconductor, inc.
fgpio x _psor field descriptions field description 31C0 ptso port set output writing to this register will update the contents of the corresponding bit in the pdor as follows: 0 corresponding bit in pdorn does not change. 1 corresponding bit in pdorn is set to logic 1. 37.3.3 port clear output register (fgpio x _pcor) this register configures whether to clear the fields of pdor. address: base address + 8h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w ptco reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 fgpio x _pcor field descriptions field description 31C0 ptco port clear output writing to this register will update the contents of the corresponding bit in the port data output register (pdor) as follows: 0 corresponding bit in pdorn does not change. 1 corresponding bit in pdorn is cleared to logic 0. 37.3.4 port toggle output register (fgpio x _ptor) address: base address + ch offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r 0 w ptto reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 fgpio x _ptor field descriptions field description 31C0 ptto port toggle output writing to this register will update the contents of the corresponding bit in the pdor as follows: chapter 37 general-purpose input/output (gpio) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 653
fgpio x _ptor field descriptions (continued) field description 0 corresponding bit in pdorn does not change. 1 corresponding bit in pdorn is set to the inverse of its existing logic state. 37.3.5 port data input register (fgpio x _pdir) address: base address + 10h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r pdi w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 fgpio x _pdir field descriptions field description 31C0 pdi port data input reads 0 at the unimplemented pins for a particular device. pins that are not configured for a digital function read 0. if the port control and interrupt module is disabled, then the corresponding bit in pdir does not update. 0 pin logic level is logic 0, or is not configured for use by digital function. 1 pin logic level is logic 1. 37.3.6 port data direction register (fgpio x _pddr) the pddr configures the individual port pins for input or output. address: base address + 14h offset bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 r pdd w reset 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 fgpio x _pddr field descriptions field description 31C0 pdd port data direction configures individual port pins for input or output. 0 pin is configured as general-purpose input, for the gpio function. 1 pin is configured as general-purpose output, for the gpio function. fgpio memory map and register definition kl04 sub-family reference manual, rev. 3.1, november 2012 654 freescale semiconductor, inc.
37.4 functional description 37.4.1 general-purpose input the logic state of each pin is available via the port data input registers, provided the pin is configured for a digital function and the corresponding port control and interrupt module is enabled. 37.4.2 general-purpose output the logic state of each pin can be controlled via the port data output registers and port data direction registers, provided the pin is configured for the gpio function. the following table depicts the conditions for a pin to be configured as input/output. if then a pin is configured for the gpio function and the corresponding port data direction register bit is clear. the pin is configured as an input. a pin is configured for the gpio function and the corresponding port data direction register bit is set. the pin is configured as an output and and the logic state of the pin is equal to the corresponding port data output register. to facilitate efficient bit manipulation on the general-purpose outputs, pin data set, pin data clear, and pin data toggle registers exist to allow one or more outputs within one port to be set, cleared, or toggled from a single register write. the corresponding port control and interrupt module does not need to be enabled to update the state of the port data direction registers and port data output registers including the set/clear/toggle registers. 37.4.3 ioport the gpio registers are also aliased to the ioport interface on the cortex-m0+ from address $f800_0000. accesses via the ioport interface occur in parallel with any instruction fetches and will therefore complete in a single cycle. if the dma attempts to access the gpio registers on the same cycle as an ioport access, then the dma access will stall until any ioport accesses have completed. chapter 37 general-purpose input/output (gpio) kl04 sub-family reference manual, rev. 3.1, november 2012 freescale semiconductor, inc. 655
during compute operation, the gpio registers remain accessible via the ioport interface only. since the clocks to the port control and interrupt modules are disabled during compute operation, the pin data input registers do not update with the current state of the pins. functional description kl04 sub-family reference manual, rev. 3.1, november 2012 656 freescale semiconductor, inc.
a-1 freescale semiconductor appendix a revision history of this document this appendix describes corrections to the this reference manual for convenience. grammatical and formatting changes are not listed here unless the meaning of something changed. a.1 changes between revisions 3.1 and 3 table a-1. changes between revisions 3.1 and 3 a.2 changes between revisions 3 and 2 table a-2. changes between revisions 3 and 2 chapter description chip configuration ? added a section of alternate clock for adc. micro trace buffer (mtb) ? updated mtb_position, mtb_master and mtb_flow registers and fields descriptions. chapter description flash memory module (ftfa) ? updated register absolute address. 12-bit digital-to-analog converter (dac) ? updated register absolute address. kl04 sub-family reference manual, rev. 3.1, november 2012
how to reach us: home page: www.freescale.com web support: http://www.freescale.com/support usa/europe or locations not listed: freescale semiconductor technical information center, el516 2100 east elliot road tempe, arizona 85284 +1-800-521-6274 or +1-480-768-2130 www.freescale.com/support europe, middle east, and africa: freescale halbleiter deutschland gmbh technical information center schatzbogen 7 81829 muenchen, germany +44 1296 380 456 (english) +46 8 52200080 (english) +49 89 92103 559 (german) +33 1 69 35 48 48 (french) www.freescale.com/support japan: freescale semiconductor japan ltd. headquarters arco tower 15f 1-8-1, shimo-meguro, meguro-ku, tokyo 153-0064 japan 0120 191014 or +81 3 5437 9125 support.japan@freescale.com asia/pacific: freescale semiconductor china ltd. exchange building 23f no. 118 jianguo road chaoyang district beijing 100022 china +86 10 5879 8000 support.asia@freescale.com document number: kl04p48m48sf1rm rev. 3.1, november 2012 information in this document is provided solely to enable system and software implementers to use freescale semiconductors products. there are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. freescale semiconductor reserves the right to make changes without further notice to any products herein. freescale semiconductor makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does freescale semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any liability, including without limitation consequential or incidental damages. "typical" parameters that may be provided in freescale semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. all operating parameters, including "typicals", must be validated for each customer application by customer's technical experts. freescale semiconductor does not convey any license under its patent rights nor the rights of others. freescale semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which failure of the freescale semiconductor product could create a situation where personal injury or death may occur. should buyer purchase or use freescale semiconductor products for any such unintended or unauthorized application, buyer shall indemnify freescale semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claims alleges that freescale semiconductor was negligent regarding the design or manufacture of the part. rohs-compliant and/or pb-free versions of freescale products have the functionality and electrical characteristics as their non-rohs-complaint and/or non-pb-free counterparts. for further information, see http://www.freescale.com or contact your freescale sales representative. for information on freescale's environmental products program, go to http://www.freescale.com/epp. freescale? and the freescale logo are trademarks of freescale semiconductor, inc. all other product or service names are the property of their respective owners. ? 2012 freescale semiconductor, inc.


▲Up To Search▲   

 
Price & Availability of MKL04Z16VFM4

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X